From 7e7b6937a61037e49948790dc88e76a961f95533 Mon Sep 17 00:00:00 2001 From: barduinor Date: Tue, 19 Sep 2023 16:05:19 -0400 Subject: [PATCH 01/34] Implemented Collection header update --- src/CollectionAdvanced.js | 2 +- src/DeployIncremental.js | 81 ++++++++++++++++++++++++++++++++------- 2 files changed, 68 insertions(+), 15 deletions(-) diff --git a/src/CollectionAdvanced.js b/src/CollectionAdvanced.js index 87357bb..db17343 100644 --- a/src/CollectionAdvanced.js +++ b/src/CollectionAdvanced.js @@ -79,7 +79,7 @@ class CollectionAdvanced extends Collection { { key: 'token', value: '{{access_token}}', - type: 'any' + type: 'string' } ] diff --git a/src/DeployIncremental.js b/src/DeployIncremental.js index d42be5d..e84a2e4 100644 --- a/src/DeployIncremental.js +++ b/src/DeployIncremental.js @@ -56,22 +56,27 @@ async function upadteCollectionHead (remoteCollection, localCollection) { const localEmptyCollection = { ...localCollection } localEmptyCollection.item = [] + // Check changes in info + const hasChangesInfo = checkInfoChanges(remoteCollection, localCollection) + // Check if there are changes in the Authorization const hasChangesAuth = checkObjectChanges(remoteCollection.collection.auth, localEmptyCollection.auth) // Check if there are changes in the Scripts (pre-request and tests) - const hasChangesScripts = checkScriptChanges(remoteCollection, localEmptyCollection) + const hasChangesPreRequestScript = checkScriptChanges('prerequest', remoteCollection, localEmptyCollection) + + const hasChangesTestScript = checkScriptChanges('test', remoteCollection, localEmptyCollection) // Check if there are changes in the Variables const hasChangesVariables = checkVariableChanges(remoteCollection, localEmptyCollection) - const hasChanges = hasChangesAuth || hasChangesScripts || hasChangesVariables + const hasChanges = hasChangesInfo || hasChangesAuth || hasChangesPreRequestScript || hasChangesTestScript || hasChangesVariables if (hasChanges) { const msg = 'Updating collection head' console.log('\n' + msg + '...') await new pmAPI.Collection(remoteCollection.collection.info.uid) - .update({ collection: localCollection }) + .update({ collection: localEmptyCollection }) .then(() => { console.log(msg, '-> OK\n') }) .catch((error) => { console.log(msg, '-> FAIL') @@ -80,8 +85,31 @@ async function upadteCollectionHead (remoteCollection, localCollection) { } return hasChanges } +const checkInfoChanges = (remoteCollection, localEmptyCollection) => { + // collection info does not have a specific id + // so we need to generate a hash and compare them + // The hash is only beig generated for name, description and schema + + const { name, description, schema } = remoteCollection.collection.info + const remoteInfo = { name, description, schema } + + const { name: localName, description: localDescription, schema: localSchema } = localEmptyCollection.info + const localInfo = { name: localName, description: localDescription, schema: localSchema } + + const remoteInfoHash = calculateHash(JSON.stringify(remoteInfo)) + const localInfoHash = calculateHash(JSON.stringify(localInfo)) + + return remoteInfoHash !== localInfoHash +} const checkObjectChanges = (remoteCollectionObject, localCollectionObject) => { + if (!remoteCollectionObject && !localCollectionObject) { + return false + } + if (!remoteCollectionObject || !localCollectionObject) { + return true + } + // certain object like auth do not have an id, // so we need to generate on and compare them const remoteCollectionAuthID = GenID(JSON.stringify(remoteCollectionObject)) @@ -89,22 +117,41 @@ const checkObjectChanges = (remoteCollectionObject, localCollectionObject) => { return remoteCollectionAuthID !== localCollectionAuthID } -const checkScriptChanges = (remoteCollection, localCollection) => { - let remoteScript = null - let localScript = null - if (remoteCollection.collection.event) { - remoteScript = JSON.stringify(remoteCollection.collection.event) +const checkScriptChanges = (scriptType, remoteCollection, localCollection) => { + const remoteScript = remoteCollection.collection.event.find(event => event.listen === scriptType) + const localScript = localCollection.event.find(event => event.listen === scriptType) + + if (!remoteScript && !localScript) { + return false } - if (localCollection.event) { - localScript = JSON.stringify(localCollection.event) + if (!remoteScript || !localScript) { + return true } + // files can be big, so we hash them + const remoteHash = calculateHash(remoteScript.script.exec[0]) + const localHash = calculateHash(localScript.script.exec[0]) - return GenID(remoteScript) !== GenID(localScript) + return remoteHash !== localHash } const checkVariableChanges = (remoteCollection, localCollection) => { - const remoteVariablesHash = GenID(JSON.stringify(remoteCollection.collection.variable)) - const localVariablesHash = GenID(JSON.stringify(localCollection.variable)) + const remoteVariables = remoteCollection.collection.variable + const localVariables = localCollection.variable.map(variable => ({ key: variable.key, value: variable.value })) + + // check if null + if (!remoteVariables && !localVariables) { + return false + } + if (!remoteVariables || !localVariables) { + return true + } + + // although the local collection does have a deterministic id + // the remote variable looses that value when it is updated + // so we need to generate an id for the remote variable + + const remoteVariablesHash = GenID(remoteVariables) + const localVariablesHash = GenID(localVariables) return remoteVariablesHash !== localVariablesHash } @@ -320,6 +367,7 @@ async function refreshRemoteCollection (remoteCollectionID) { }) return remoteCollection } + // Handle axios error const handlePostmanAPIError = (error) => { if (error.response) { @@ -336,10 +384,15 @@ const handlePostmanAPIError = (error) => { } } const { method, url, data } = error.config - console.log('REQUEST DETAILS', { method, url, data }) + const smallData = data.substring(0, 1000) + console.log('REQUEST DETAILS', { method, url, smallData }) process.exit(1) } +const calculateHash = (stringToHash) => { + return crypto.createHash('sha256').update(stringToHash).digest('hex') +} + module.exports = { deployIncremental } From 12a84c4fd0f1ad0a56a01faeb85758bcdf4685c4 Mon Sep 17 00:00:00 2001 From: barduinor Date: Tue, 19 Sep 2023 16:32:50 -0400 Subject: [PATCH 02/34] Unable to sort folders --- src/DeployIncremental.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/DeployIncremental.js b/src/DeployIncremental.js index e84a2e4..db16712 100644 --- a/src/DeployIncremental.js +++ b/src/DeployIncremental.js @@ -201,6 +201,21 @@ async function mergeFolders (remoteCollection, localCollection) { handlePostmanAPIError(error) }) } + + // sort folders is not supported for now + // const order = localFolders.map(folder => folder.id) + // const msg = ' Sorting folders' + + // // create a temporsary root folder + // const rootFolder = await new pmAPI.Folder(remoteCollection.collection.info.uid) + // .create({ id: GenID(), name: 'root', folders: order }) + // .catch((error) => { + // console.log(msg, '-> FAIL') + // handlePostmanAPIError(error) + // }) + // console.log('root folder', rootFolder) + // // move all remote folders into root folder + return hasChanges } From 073fc477b342a1e5a678bc9322f69c9b9331e5c2 Mon Sep 17 00:00:00 2001 From: barduinor Date: Tue, 19 Sep 2023 18:28:00 -0400 Subject: [PATCH 03/34] Detect folder sort changes to deploy collection header + check requests and responses object --- src/DeployIncremental.js | 75 +++++++++++++++++++++++++++++++--------- src/PostmanCovertions.js | 5 +-- 2 files changed, 61 insertions(+), 19 deletions(-) diff --git a/src/DeployIncremental.js b/src/DeployIncremental.js index db16712..d28fa82 100644 --- a/src/DeployIncremental.js +++ b/src/DeployIncremental.js @@ -22,27 +22,42 @@ const deployIncremental = async (privateRemoteCollectionId, localCollection, pub console.log('Incremental deployment of collection ', localCollection.info.name) - const collectioHeadHasChanged = await upadteCollectionHead(remoteCollection, localCollection) + // const collectioHeadHasChanged = + await upadteCollectionHead(remoteCollection, localCollection) remoteCollection = await refreshRemoteCollection(privateRemoteCollectionId) - const foldersHaveChanged = await mergeFolders(remoteCollection, localCollection) + + // const foldersHaveChanged = + await mergeFolders(remoteCollection, localCollection) remoteCollection = await refreshRemoteCollection(privateRemoteCollectionId) - const requestsHaveChanged = await mergeRequests(remoteCollection, localCollection) + + // const requestsHaveChanged = + await mergeRequests(remoteCollection, localCollection) remoteCollection = await refreshRemoteCollection(privateRemoteCollectionId) - const responsesHaveChanged = await mergeResponses(remoteCollection, localCollection) - if (collectioHeadHasChanged || foldersHaveChanged || requestsHaveChanged || responsesHaveChanged) { - const msg = 'Merging to public collection' - console.log('\n' + msg + '...') - await new pmAPI.Collection(privateRemoteCollectionId).merge(publicRemoteCollectionId) - .then(() => { console.log(msg, '-> OK\n') }) - .catch((error) => { - console.log(msg, '-> FAIL') - handlePostmanAPIError(error) - }) - } + // const responsesHaveChanged = + await mergeResponses(remoteCollection, localCollection) + + // should we always merge into the public collection? + // There is teh case that if an error happens in the merge phase + // the private collection is fully updated + // and in the next run the public collection will NOT be updated + // because there are no changes in the private collection + + // if (!(collectioHeadHasChanged || foldersHaveChanged || requestsHaveChanged || responsesHaveChanged)) { + // console.log('Incremental deployment of collection ', localCollection.info.name, ' completed\n\n') + // return + // } + const msg = 'Merging to public collection' + console.log('\n' + msg + '...') + await new pmAPI.Collection(privateRemoteCollectionId).merge(publicRemoteCollectionId) + .then(() => { console.log(msg, '-> OK\n') }) + .catch((error) => { + console.log(msg, '-> FAIL') + handlePostmanAPIError(error) + }) console.log('Incremental deployment of collection ', localCollection.info.name, ' completed\n\n') } @@ -70,7 +85,16 @@ async function upadteCollectionHead (remoteCollection, localCollection) { // Check if there are changes in the Variables const hasChangesVariables = checkVariableChanges(remoteCollection, localEmptyCollection) - const hasChanges = hasChangesInfo || hasChangesAuth || hasChangesPreRequestScript || hasChangesTestScript || hasChangesVariables + const hasFolderSortChanges = checkFolderSortChanges(remoteCollection, localCollection) + + const hasChanges = ( + hasFolderSortChanges || + hasChangesInfo || + hasChangesAuth || + hasChangesPreRequestScript || + hasChangesTestScript || + hasChangesVariables + ) if (hasChanges) { const msg = 'Updating collection head' @@ -85,6 +109,19 @@ async function upadteCollectionHead (remoteCollection, localCollection) { } return hasChanges } + +const checkFolderSortChanges = (remoteCollection, localCollection) => { + const remoteFolders = remoteCollection.collection.item + .map(folder => ({ id: folder.id })) + const localFolders = localCollection.item + .map(folder => ({ id: folder.id })) + + const remoteFoldersHash = GenID(JSON.stringify(remoteFolders)) + const localFoldersHash = GenID(JSON.stringify(localFolders)) + + return remoteFoldersHash !== localFoldersHash +} + const checkInfoChanges = (remoteCollection, localEmptyCollection) => { // collection info does not have a specific id // so we need to generate a hash and compare them @@ -249,16 +286,20 @@ async function mergeRequests (remoteCollection, localCollection) { for (const request of newRequests) { const pmRequest = pmConvert.requestFromLocal(request) const msg = ` Creating new request [${request.name}]` - // console.log('request: \n', JSON.stringify(request, 2)) + await new pmAPI.Request(remoteCollection.collection.info.uid) .create(pmRequest, localFolder.id) - .then(() => { + .then((req) => { console.log(msg, '-> OK') + return req }) .catch((error) => { console.log(msg, '-> FAIL') handlePostmanAPIError(error) }) + // console.log('\nequest', request) + // console.log('\npmRequest', pmRequest) + // console.log('\nremoteRequest', remoteRequest) } // delete old requests diff --git a/src/PostmanCovertions.js b/src/PostmanCovertions.js index 8dcd650..2fdff27 100644 --- a/src/PostmanCovertions.js +++ b/src/PostmanCovertions.js @@ -41,6 +41,7 @@ const requestFromLocal = (localRequest) => { let headerData = [] if (localRequest.request.header) { headerData = dataFromLocalURLEncode(localRequest.request.header) + .map((header) => ({ key: header.key, value: header.value, enabled: header.enabled, description: header.description })) } const request = { @@ -92,7 +93,7 @@ const requestFromLocal = (localRequest) => { } const responseFromLocal = (localResponse) => { - // if () + const headers = localResponse.header.map((item) => ({ key: item.key, value: item.value })) const response = { // owner: '8119550', // lastUpdatedBy: '8119550', @@ -108,7 +109,7 @@ const responseFromLocal = (localResponse) => { detail: '' }, // time: null, - headers: localResponse.header, // + headers, // cookies: [], mime: null, text: localResponse.body, // From 85d5b5c96c89b05c24f995375d09c485b19cb530 Mon Sep 17 00:00:00 2001 From: barduinor Date: Tue, 19 Sep 2023 18:38:46 -0400 Subject: [PATCH 04/34] Deploy advanced collection --- .github/workflows/deploy.yml | 43 +++++++++++++++++++++++++++++++++++- package.json | 1 + 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 838b685..e253c84 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -89,4 +89,45 @@ jobs: SLACK_USERNAME: GitHub Actions SLACK_AVATAR: "https://avatars3.githubusercontent.com/u/8659759?s=200&v=4" with: - args: "Deployed Japanese Postman collection :rocket:" \ No newline at end of file + args: "Deployed Japanese Postman collection :rocket:" + + + # Deploys the Advanced version + deploy-adv: + runs-on: ubuntu-latest + timeout-minutes: 20 + needs: deploy-en + + env: + LOCALES: "en" + JP_OAS3_REPO: "https://github.com/box/box-openapi.git#jp" + PRIVATE_EN_POSTMAN_COLLECTION_ID: "8119550-1ca6cb64-7560-4f24-a2b5-89ba095b1c17" + PUBLIC_EN_POSTMAN_COLLECTION_ID: "8119550-373aba62-5af5-459b-b9a4-e9db77f947a5" + POSTMAN_API_KEY: ${{ secrets.POSTMAN_API_KEY }} + + strategy: + matrix: + node-version: [18.x] + + steps: + - name: Check out the repo + uses: actions/checkout@v3 + + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + + - name: Deploy the collection + run: | + yarn install + yarn releaseAdvanced en + + - name: Send Slack notification + uses: Ilshidur/action-slack@2.0.2 + env: + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} + SLACK_USERNAME: GitHub Actions + SLACK_AVATAR: "https://avatars3.githubusercontent.com/u/8659759?s=200&v=4" + with: + args: "Deployed Advanced Postman collection :rocket:" \ No newline at end of file diff --git a/package.json b/package.json index 3f67f3c..d067bb7 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ "prebuild:all": "yarn prebuild", "convert": "node -e 'require(\"./src/scripts/convert.js\").convert()'", "convert:all": "node -e 'require(\"./src/scripts/convert.js\").convertAll()'", + "prereleaseAdvanced": "yarn build:all", "prerelease": "yarn build:all", "prerelease:all": "yarn build:all", "release": "node -e 'require(\"./src/scripts/release.js\").release()'", From b3cf6ab3e206c389e96905665e61ed38b0e5f4d2 Mon Sep 17 00:00:00 2001 From: barduinor Date: Tue, 19 Sep 2023 18:41:20 -0400 Subject: [PATCH 05/34] remove dependency on classic collections for the deploy of the advanced collection --- .github/workflows/deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index e253c84..5323302 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -96,7 +96,7 @@ jobs: deploy-adv: runs-on: ubuntu-latest timeout-minutes: 20 - needs: deploy-en + # needs: deploy-jp env: LOCALES: "en" From bf8be434b1e92d546c1b0fb8887298732e73f5b5 Mon Sep 17 00:00:00 2001 From: barduinor Date: Tue, 19 Sep 2023 18:50:09 -0400 Subject: [PATCH 06/34] fix deploy issue where git hub repo was not being found --- .github/workflows/deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 5323302..000555c 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -100,7 +100,7 @@ jobs: env: LOCALES: "en" - JP_OAS3_REPO: "https://github.com/box/box-openapi.git#jp" + EN_OAS3_REPO: "https://github.com/box/box-openapi.git#jp" PRIVATE_EN_POSTMAN_COLLECTION_ID: "8119550-1ca6cb64-7560-4f24-a2b5-89ba095b1c17" PUBLIC_EN_POSTMAN_COLLECTION_ID: "8119550-373aba62-5af5-459b-b9a4-e9db77f947a5" POSTMAN_API_KEY: ${{ secrets.POSTMAN_API_KEY }} From 4a13aabafc339340fdc74225deda360ea89cf7e7 Mon Sep 17 00:00:00 2001 From: barduinor Date: Tue, 19 Sep 2023 19:09:27 -0400 Subject: [PATCH 07/34] fix deploy issue where build was failing --- .github/workflows/deploy.yml | 2 ++ package.json | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 000555c..1c07634 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -121,6 +121,8 @@ jobs: - name: Deploy the collection run: | yarn install + yarn pull + yarn convertAdvanced en yarn releaseAdvanced en - name: Send Slack notification diff --git a/package.json b/package.json index d067bb7..3f67f3c 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,6 @@ "prebuild:all": "yarn prebuild", "convert": "node -e 'require(\"./src/scripts/convert.js\").convert()'", "convert:all": "node -e 'require(\"./src/scripts/convert.js\").convertAll()'", - "prereleaseAdvanced": "yarn build:all", "prerelease": "yarn build:all", "prerelease:all": "yarn build:all", "release": "node -e 'require(\"./src/scripts/release.js\").release()'", From 351d86d8ec961ff010b5d4af2e680dbf7afa5cc2 Mon Sep 17 00:00:00 2001 From: barduinor Date: Tue, 19 Sep 2023 19:19:35 -0400 Subject: [PATCH 08/34] fix deploy issue env vars incorrect --- .github/workflows/deploy.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 1c07634..0321807 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -101,8 +101,8 @@ jobs: env: LOCALES: "en" EN_OAS3_REPO: "https://github.com/box/box-openapi.git#jp" - PRIVATE_EN_POSTMAN_COLLECTION_ID: "8119550-1ca6cb64-7560-4f24-a2b5-89ba095b1c17" - PUBLIC_EN_POSTMAN_COLLECTION_ID: "8119550-373aba62-5af5-459b-b9a4-e9db77f947a5" + PRIVATE_EN_POSTMAN_COLLECTION_ADVANCED_ID: "8119550-1ca6cb64-7560-4f24-a2b5-89ba095b1c17" + PUBLIC_EN_POSTMAN_COLLECTION_ADVANCED_ID: "8119550-373aba62-5af5-459b-b9a4-e9db77f947a5" POSTMAN_API_KEY: ${{ secrets.POSTMAN_API_KEY }} strategy: From b37504fe2f6ad0d4ef29446b7f8c0203070f8df8 Mon Sep 17 00:00:00 2001 From: barduinor Date: Tue, 19 Sep 2023 19:39:44 -0400 Subject: [PATCH 09/34] created separete deployAdvance git workflow --- .github/workflows/deploy.yml | 49 ++---------------------- .github/workflows/deployAdvanced.yml | 57 ++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 46 deletions(-) create mode 100644 .github/workflows/deployAdvanced.yml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 0321807..7023edc 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -4,9 +4,9 @@ name: Deploy # Defines when this action should be run on: # Run on any push to main - push: - branches: - - main + # push: + # branches: + # - main # Run when a repository dispatch event is received repository_dispatch: types: [openapi-update] @@ -90,46 +90,3 @@ jobs: SLACK_AVATAR: "https://avatars3.githubusercontent.com/u/8659759?s=200&v=4" with: args: "Deployed Japanese Postman collection :rocket:" - - - # Deploys the Advanced version - deploy-adv: - runs-on: ubuntu-latest - timeout-minutes: 20 - # needs: deploy-jp - - env: - LOCALES: "en" - EN_OAS3_REPO: "https://github.com/box/box-openapi.git#jp" - PRIVATE_EN_POSTMAN_COLLECTION_ADVANCED_ID: "8119550-1ca6cb64-7560-4f24-a2b5-89ba095b1c17" - PUBLIC_EN_POSTMAN_COLLECTION_ADVANCED_ID: "8119550-373aba62-5af5-459b-b9a4-e9db77f947a5" - POSTMAN_API_KEY: ${{ secrets.POSTMAN_API_KEY }} - - strategy: - matrix: - node-version: [18.x] - - steps: - - name: Check out the repo - uses: actions/checkout@v3 - - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v3 - with: - node-version: ${{ matrix.node-version }} - - - name: Deploy the collection - run: | - yarn install - yarn pull - yarn convertAdvanced en - yarn releaseAdvanced en - - - name: Send Slack notification - uses: Ilshidur/action-slack@2.0.2 - env: - SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} - SLACK_USERNAME: GitHub Actions - SLACK_AVATAR: "https://avatars3.githubusercontent.com/u/8659759?s=200&v=4" - with: - args: "Deployed Advanced Postman collection :rocket:" \ No newline at end of file diff --git a/.github/workflows/deployAdvanced.yml b/.github/workflows/deployAdvanced.yml new file mode 100644 index 0000000..eb9b112 --- /dev/null +++ b/.github/workflows/deployAdvanced.yml @@ -0,0 +1,57 @@ +# The name of this GH action +name: Deploy + +# Defines when this action should be run +on: + # Run on any push to main + push: + branches: + - main + # Run when a repository dispatch event is received + repository_dispatch: + types: [openapi-update] + +jobs: +# Deploys the Advanced version + deploy-adv: + runs-on: ubuntu-latest + timeout-minutes: 20 + # needs: deploy-jp + + env: + LOCALES: "en" + EN_OAS3_REPO: "https://github.com/box/box-openapi.git#en" + PRIVATE_EN_POSTMAN_COLLECTION_ADVANCED_ID: "8119550-1ca6cb64-7560-4f24-a2b5-89ba095b1c17" + PUBLIC_EN_POSTMAN_COLLECTION_ADVANCED_ID: "8119550-373aba62-5af5-459b-b9a4-e9db77f947a5" + CONVERT_LOG: true + POSTMAN_API_KEY: ${{ secrets.POSTMAN_API_KEY }} + + strategy: + matrix: + node-version: [18.x] + + steps: + - name: Check out the repo + uses: actions/checkout@v3 + + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + + - name: Deploy the collection + run: | + yarn install + yarn clean + yarn pull + yarn convertAdvanced en + yarn releaseAdvanced en + + - name: Send Slack notification + uses: Ilshidur/action-slack@2.0.2 + env: + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} + SLACK_USERNAME: GitHub Actions + SLACK_AVATAR: "https://avatars3.githubusercontent.com/u/8659759?s=200&v=4" + with: + args: "Deployed Advanced Postman collection :rocket:" \ No newline at end of file From 0c63d3ac7337f0074d034f89fbfbb95189461868 Mon Sep 17 00:00:00 2001 From: barduinor Date: Tue, 19 Sep 2023 19:42:20 -0400 Subject: [PATCH 10/34] created separete deployAdvance git workflow --- .github/workflows/deployAdvanced.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deployAdvanced.yml b/.github/workflows/deployAdvanced.yml index eb9b112..d1bc64a 100644 --- a/.github/workflows/deployAdvanced.yml +++ b/.github/workflows/deployAdvanced.yml @@ -1,5 +1,5 @@ # The name of this GH action -name: Deploy +name: Deploy Advanced # Defines when this action should be run on: From b19fc8f6f7f1d8f512ae8fe288e0eefa2e268a1f Mon Sep 17 00:00:00 2001 From: barduinor Date: Wed, 20 Sep 2023 10:15:47 -0400 Subject: [PATCH 11/34] replace environment name by environment type --- src/events/collectionPreReqScript.js | 39 ++++++++++++++-------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/src/events/collectionPreReqScript.js b/src/events/collectionPreReqScript.js index f65ceed..9f39238 100644 --- a/src/events/collectionPreReqScript.js +++ b/src/events/collectionPreReqScript.js @@ -6,14 +6,14 @@ /* eslint-disable object-shorthand */ const check_environment = () => { // check current environment name - const env_name = pm.environment.name + const env_type = pm.environment.get('box_env_type') - if (!env_name) { throw new Error('No environment selected. Please select one of the supported Box environments') } + if (!env_type) { throw new Error('Unable to identify environment type. Please select a supported environment') } const error_msg = [] // check environment variables - if (env_name === DEV_TOKEN) { + if (env_type === EnvType.BEARER) { const access_token = pm.environment.get('access_token') if (!access_token) { error_msg.push('Access Token') } } else { @@ -23,13 +23,12 @@ const check_environment = () => { if (!client_id) { error_msg.push('Client_id') } if (!client_secret) { error_msg.push('Client secret') } } - - if (env_name === OAUTH) { + if (env_type === EnvType.OAUTH) { const refresh_token = pm.environment.get('refresh_token') if (!refresh_token) { error_msg.push('Refresh token') } } - if (env_name === CCG || env_name === JWT) { + if (env_type === EnvType.CCG || env_type === EnvType.JWT) { const box_subject_type = pm.environment.get('box_subject_type') const box_subject_id = pm.environment.get('box_subject_id') @@ -43,7 +42,7 @@ const check_environment = () => { if (!box_subject_id) { error_msg.push('Box subject id') } } - if (env_name === JWT) { + if (env_type === EnvType.JWT) { const key_id = pm.environment.get('key_id') const private_key_encrypted = pm.environment.get('private_key_encrypted') const private_key_passphrase = pm.environment.get('private_key_passphrase') @@ -57,7 +56,7 @@ const check_environment = () => { // there is an error throw new Error('Invalid enviroment variables: ' + error_msg.join(', ')) } - return env_name + return env_type } const get_token = (urlencoded) => { @@ -198,7 +197,7 @@ const box_postman = () => { // if authotization type is not null (not inherited) then exit the script if (pm.request.auth) { return } - const env = check_environment() + const env_type = check_environment() // determine if the Access Token has expired const expiresAt = pm.environment.get('expires_at') || 0 @@ -206,21 +205,21 @@ const box_postman = () => { // refresh the access token if needed if (is_expired) { - switch (env) { - case DEV_TOKEN: + switch (env_type) { + case EnvType.BEARER: console.info('can`t refresh developer token, sending as is...') break - case OAUTH: + case EnvType.OAUTH: /* eslint-disable no-case-declarations */ const current_refresh_expiration = pm.environment.get('refresh_token_expires_at') || 0 const is_expired = Date.now() > Number(current_refresh_expiration) if (is_expired) { throw new Error('Refresh token has expired') } refresh_oauth() break - case CCG: + case EnvType.CCG: refresh_ccg() break - case JWT: + case EnvType.JWT: const assertion = get_jwt_assertion() refresh_jwt(assertion) break @@ -230,10 +229,12 @@ const box_postman = () => { } } -// Defined environment names -const DEV_TOKEN = 'Box DevToken' -const OAUTH = 'Box oAuth 2.0' -const CCG = 'Box CCG' -const JWT = 'Box JWT' +// Defined environment types +const EnvType = { + BEARER: 'BEARER', + OAUTH: 'OAUTH', + CCG: 'CCG', + JWT: 'JWT' +} box_postman() From 20ce840a64f38f32ea1e097e9a6b6465f0b7b445 Mon Sep 17 00:00:00 2001 From: barduinor Date: Wed, 20 Sep 2023 13:56:00 -0400 Subject: [PATCH 12/34] replace environment name by environment type --- src/events/collectionPreReqScript.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/events/collectionPreReqScript.js b/src/events/collectionPreReqScript.js index 9f39238..e6337e3 100644 --- a/src/events/collectionPreReqScript.js +++ b/src/events/collectionPreReqScript.js @@ -207,7 +207,7 @@ const box_postman = () => { if (is_expired) { switch (env_type) { case EnvType.BEARER: - console.info('can`t refresh developer token, sending as is...') + console.info('can`t refresh bearer token, sending as is...') break case EnvType.OAUTH: /* eslint-disable no-case-declarations */ From 2222699f6fa61cd1ad8d0b59d3596d0da66dc459 Mon Sep 17 00:00:00 2001 From: barduinor Date: Wed, 20 Sep 2023 15:30:55 -0400 Subject: [PATCH 13/34] update pre-script to read the RSASign lib from the environment variable --- src/events/collectionPreReqScript.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/events/collectionPreReqScript.js b/src/events/collectionPreReqScript.js index e6337e3..08cab52 100644 --- a/src/events/collectionPreReqScript.js +++ b/src/events/collectionPreReqScript.js @@ -128,13 +128,13 @@ async function refresh_oauth () { } function get_jwt_assertion () { - // jsrsasign lib - const jsrsasign_lib = pm.environment.get('jsrsasign') + // libJSRSASign lib + const libJSRSASign = pm.collectionVariables.get('libJSRSASign') /* eslint-disable no-global-assign */ navigator = {} window = {} /* eslint-disable no-eval */ - eval(jsrsasign_lib) + eval(libJSRSASign) // UUID const uuid = require('uuid') @@ -169,9 +169,9 @@ function get_jwt_assertion () { const jwt = KJUR.jws.JWS.sign(null, header, claims, private_key) - console.log(`header: ${JSON.stringify(header)}`) - console.log(`claim set: ${JSON.stringify(claims)}`) - console.log('JWT Assertion: ', jwt) + // console.log(`header: ${JSON.stringify(header)}`) + // console.log(`claim set: ${JSON.stringify(claims)}`) + // console.log('JWT Assertion: ', jwt) return jwt } @@ -197,6 +197,8 @@ const box_postman = () => { // if authotization type is not null (not inherited) then exit the script if (pm.request.auth) { return } + // console.info('Collection variables',pm.collectionVariables.toObject()) + const env_type = check_environment() // determine if the Access Token has expired From a39824d987bb3fba6bb3c1c072fda0117c0a10b4 Mon Sep 17 00:00:00 2001 From: barduinor Date: Wed, 20 Sep 2023 15:44:26 -0400 Subject: [PATCH 14/34] added lib JsRSASign as resource file --- src/events/libJsRSASign.min.js | 224 +++++++++++++++++++++++++++++++++ 1 file changed, 224 insertions(+) create mode 100644 src/events/libJsRSASign.min.js diff --git a/src/events/libJsRSASign.min.js b/src/events/libJsRSASign.min.js new file mode 100644 index 0000000..868d870 --- /dev/null +++ b/src/events/libJsRSASign.min.js @@ -0,0 +1,224 @@ +/* jsrsasign(all) 10.8.6 (2023-04-26) + * (c) 2010-2023 Kenji Urushima | kjur.github.io/jsrsasign/license + */ +/* eslint-disable no-use-before-define */ +var VERSION = "10.8.6"; +var VERSION_FULL = "jsrsasign(all) 10.8.6 (2023-04-26) (c) 2010-2023 Kenji Urushima | kjur.github.io/jsrsasign/license"; +/*! CryptoJS v3.1.2 core-fix.js + * code.google.com/p/crypto-js + * (c) 2009-2013 by Jeff Mott. All rights reserved. + * code.google.com/p/crypto-js/wiki/License + * THIS IS FIX of 'core.js' to fix Hmac issue. + * https://code.google.com/p/crypto-js/issues/detail?id=84 + * https://crypto-js.googlecode.com/svn-history/r667/branches/3.x/src/core.js + */ +var CryptoJS=CryptoJS||(function(e,g){var a={};var b=a.lib={};var j=b.Base=(function(){function n(){}return{extend:function(p){n.prototype=this;var o=new n();if(p){o.mixIn(p)}if(!o.hasOwnProperty("init")){o.init=function(){o.$super.init.apply(this,arguments)}}o.init.prototype=o;o.$super=this;return o},create:function(){var o=this.extend();o.init.apply(o,arguments);return o},init:function(){},mixIn:function(p){for(var o in p){if(p.hasOwnProperty(o)){this[o]=p[o]}}if(p.hasOwnProperty("toString")){this.toString=p.toString}},clone:function(){return this.init.prototype.extend(this)}}}());var l=b.WordArray=j.extend({init:function(o,n){o=this.words=o||[];if(n!=g){this.sigBytes=n}else{this.sigBytes=o.length*4}},toString:function(n){return(n||h).stringify(this)},concat:function(t){var q=this.words;var p=t.words;var n=this.sigBytes;var s=t.sigBytes;this.clamp();if(n%4){for(var r=0;r>>2]>>>(24-(r%4)*8))&255;q[(n+r)>>>2]|=o<<(24-((n+r)%4)*8)}}else{for(var r=0;r>>2]=p[r>>>2]}}this.sigBytes+=s;return this},clamp:function(){var o=this.words;var n=this.sigBytes;o[n>>>2]&=4294967295<<(32-(n%4)*8);o.length=e.ceil(n/4)},clone:function(){var n=j.clone.call(this);n.words=this.words.slice(0);return n},random:function(p){var o=[];for(var n=0;n>>2]>>>(24-(n%4)*8))&255;q.push((s>>>4).toString(16));q.push((s&15).toString(16))}return q.join("")},parse:function(p){var n=p.length;var q=[];for(var o=0;o>>3]|=parseInt(p.substr(o,2),16)<<(24-(o%8)*4)}return new l.init(q,n/2)}};var d=m.Latin1={stringify:function(q){var r=q.words;var p=q.sigBytes;var n=[];for(var o=0;o>>2]>>>(24-(o%4)*8))&255;n.push(String.fromCharCode(s))}return n.join("")},parse:function(p){var n=p.length;var q=[];for(var o=0;o>>2]|=(p.charCodeAt(o)&255)<<(24-(o%4)*8)}return new l.init(q,n)}};var c=m.Utf8={stringify:function(n){try{return decodeURIComponent(escape(d.stringify(n)))}catch(o){throw new Error("Malformed UTF-8 data")}},parse:function(n){return d.parse(unescape(encodeURIComponent(n)))}};var i=b.BufferedBlockAlgorithm=j.extend({reset:function(){this._data=new l.init();this._nDataBytes=0},_append:function(n){if(typeof n=="string"){n=c.parse(n)}this._data.concat(n);this._nDataBytes+=n.sigBytes},_process:function(w){var q=this._data;var x=q.words;var n=q.sigBytes;var t=this.blockSize;var v=t*4;var u=n/v;if(w){u=e.ceil(u)}else{u=e.max((u|0)-this._minBufferSize,0)}var s=u*t;var r=e.min(s*4,n);if(s){for(var p=0;p>>2]&255}};f.BlockCipher=n.extend({cfg:n.cfg.extend({mode:m,padding:h}),reset:function(){n.reset.call(this);var a=this.cfg,b=a.iv,a=a.mode;if(this._xformMode==this._ENC_XFORM_MODE)var c=a.createEncryptor;else c=a.createDecryptor,this._minBufferSize=1; +this._mode=c.call(a,this,b&&b.words)},_doProcessBlock:function(a,b){this._mode.processBlock(a,b)},_doFinalize:function(){var a=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){a.pad(this._data,this.blockSize);var b=this._process(!0)}else b=this._process(!0),a.unpad(b);return b},blockSize:4});var p=f.CipherParams=k.extend({init:function(a){this.mixIn(a)},toString:function(a){return(a||this.formatter).stringify(this)}}),m=(g.format={}).OpenSSL={stringify:function(a){var b=a.ciphertext;a=a.salt; +return(a?l.create([1398893684,1701076831]).concat(a).concat(b):b).toString(r)},parse:function(a){a=r.parse(a);var b=a.words;if(1398893684==b[0]&&1701076831==b[1]){var c=l.create(b.slice(2,4));b.splice(0,4);a.sigBytes-=16}return p.create({ciphertext:a,salt:c})}},j=f.SerializableCipher=k.extend({cfg:k.extend({format:m}),encrypt:function(a,b,c,d){d=this.cfg.extend(d);var e=a.createEncryptor(c,d);b=e.finalize(b);e=e.cfg;return p.create({ciphertext:b,key:c,iv:e.iv,algorithm:a,mode:e.mode,padding:e.padding, +blockSize:a.blockSize,formatter:d.format})},decrypt:function(a,b,c,d){d=this.cfg.extend(d);b=this._parse(b,d.format);return a.createDecryptor(c,d).finalize(b.ciphertext)},_parse:function(a,b){return"string"==typeof a?b.parse(a,this):a}}),g=(g.kdf={}).OpenSSL={execute:function(a,b,c,d){d||(d=l.random(8));a=v.create({keySize:b+c}).compute(a,d);c=l.create(a.words.slice(b),4*c);a.sigBytes=4*b;return p.create({key:a,iv:c,salt:d})}},s=f.PasswordBasedCipher=j.extend({cfg:j.cfg.extend({kdf:g}),encrypt:function(a, +b,c,d){d=this.cfg.extend(d);c=d.kdf.execute(c,a.keySize,a.ivSize);d.iv=c.iv;a=j.encrypt.call(this,a,b,c.key,d);a.mixIn(c);return a},decrypt:function(a,b,c,d){d=this.cfg.extend(d);b=this._parse(b,d.format);c=d.kdf.execute(c,a.keySize,a.ivSize,b.salt);d.iv=c.iv;return j.decrypt.call(this,a,b,c.key,d)}})}(); +/* +CryptoJS v3.1.2 aes.js +code.google.com/p/crypto-js +(c) 2009-2013 by Jeff Mott. All rights reserved. +code.google.com/p/crypto-js/wiki/License +*/ +(function(){for(var q=CryptoJS,x=q.lib.BlockCipher,r=q.algo,j=[],y=[],z=[],A=[],B=[],C=[],s=[],u=[],v=[],w=[],g=[],k=0;256>k;k++)g[k]=128>k?k<<1:k<<1^283;for(var n=0,l=0,k=0;256>k;k++){var f=l^l<<1^l<<2^l<<3^l<<4,f=f>>>8^f&255^99;j[n]=f;y[f]=n;var t=g[n],D=g[t],E=g[D],b=257*g[f]^16843008*f;z[n]=b<<24|b>>>8;A[n]=b<<16|b>>>16;B[n]=b<<8|b>>>24;C[n]=b;b=16843009*E^65537*D^257*t^16843008*n;s[f]=b<<24|b>>>8;u[f]=b<<16|b>>>16;v[f]=b<<8|b>>>24;w[f]=b;n?(n=t^g[g[g[E^t]]],l^=g[g[l]]):n=l=1}var F=[0,1,2,4,8, +16,32,64,128,27,54],r=r.AES=x.extend({_doReset:function(){for(var c=this._key,e=c.words,a=c.sigBytes/4,c=4*((this._nRounds=a+6)+1),b=this._keySchedule=[],h=0;h>>24]<<24|j[d>>>16&255]<<16|j[d>>>8&255]<<8|j[d&255]):(d=d<<8|d>>>24,d=j[d>>>24]<<24|j[d>>>16&255]<<16|j[d>>>8&255]<<8|j[d&255],d^=F[h/a|0]<<24);b[h]=b[h-a]^d}e=this._invKeySchedule=[];for(a=0;aa||4>=h?d:s[j[d>>>24]]^u[j[d>>>16&255]]^v[j[d>>> +8&255]]^w[j[d&255]]},encryptBlock:function(c,e){this._doCryptBlock(c,e,this._keySchedule,z,A,B,C,j)},decryptBlock:function(c,e){var a=c[e+1];c[e+1]=c[e+3];c[e+3]=a;this._doCryptBlock(c,e,this._invKeySchedule,s,u,v,w,y);a=c[e+1];c[e+1]=c[e+3];c[e+3]=a},_doCryptBlock:function(c,e,a,b,h,d,j,m){for(var n=this._nRounds,f=c[e]^a[0],g=c[e+1]^a[1],k=c[e+2]^a[2],p=c[e+3]^a[3],l=4,t=1;t>>24]^h[g>>>16&255]^d[k>>>8&255]^j[p&255]^a[l++],r=b[g>>>24]^h[k>>>16&255]^d[p>>>8&255]^j[f&255]^a[l++],s= +b[k>>>24]^h[p>>>16&255]^d[f>>>8&255]^j[g&255]^a[l++],p=b[p>>>24]^h[f>>>16&255]^d[g>>>8&255]^j[k&255]^a[l++],f=q,g=r,k=s;q=(m[f>>>24]<<24|m[g>>>16&255]<<16|m[k>>>8&255]<<8|m[p&255])^a[l++];r=(m[g>>>24]<<24|m[k>>>16&255]<<16|m[p>>>8&255]<<8|m[f&255])^a[l++];s=(m[k>>>24]<<24|m[p>>>16&255]<<16|m[f>>>8&255]<<8|m[g&255])^a[l++];p=(m[p>>>24]<<24|m[f>>>16&255]<<16|m[g>>>8&255]<<8|m[k&255])^a[l++];c[e]=q;c[e+1]=r;c[e+2]=s;c[e+3]=p},keySize:8});q.AES=x._createHelper(r)})(); +/* +CryptoJS v3.1.2 tripledes-min.js +code.google.com/p/crypto-js +(c) 2009-2013 by Jeff Mott. All rights reserved. +code.google.com/p/crypto-js/wiki/License +*/ +(function(){function j(b,c){var a=(this._lBlock>>>b^this._rBlock)&c;this._rBlock^=a;this._lBlock^=a<>>b^this._lBlock)&c;this._lBlock^=a;this._rBlock^=a<a;a++){var f=q[a]-1;c[a]=b[f>>>5]>>>31-f%32&1}b=this._subKeys=[];for(f=0;16>f;f++){for(var d=b[f]=[],e=r[f],a=0;24>a;a++)d[a/6|0]|=c[(p[a]-1+e)%28]<<31-a%6,d[4+(a/6|0)]|=c[28+(p[a+24]-1+e)%28]<<31-a%6;d[0]=d[0]<<1|d[0]>>>31;for(a=1;7>a;a++)d[a]>>>= +4*(a-1)+3;d[7]=d[7]<<5|d[7]>>>27}c=this._invSubKeys=[];for(a=0;16>a;a++)c[a]=b[15-a]},encryptBlock:function(b,c){this._doCryptBlock(b,c,this._subKeys)},decryptBlock:function(b,c){this._doCryptBlock(b,c,this._invSubKeys)},_doCryptBlock:function(b,c,a){this._lBlock=b[c];this._rBlock=b[c+1];j.call(this,4,252645135);j.call(this,16,65535);l.call(this,2,858993459);l.call(this,8,16711935);j.call(this,1,1431655765);for(var f=0;16>f;f++){for(var d=a[f],e=this._lBlock,h=this._rBlock,g=0,k=0;8>k;k++)g|=s[k][((h^ +d[k])&t[k])>>>0];this._lBlock=h;this._rBlock=e^g}a=this._lBlock;this._lBlock=this._rBlock;this._rBlock=a;j.call(this,1,1431655765);l.call(this,8,16711935);l.call(this,2,858993459);j.call(this,16,65535);j.call(this,4,252645135);b[c]=this._lBlock;b[c+1]=this._rBlock},keySize:2,ivSize:2,blockSize:2});h.DES=e._createHelper(m);g=g.TripleDES=e.extend({_doReset:function(){var b=this._key.words;this._des1=m.createEncryptor(n.create(b.slice(0,2)));this._des2=m.createEncryptor(n.create(b.slice(2,4)));this._des3= +m.createEncryptor(n.create(b.slice(4,6)))},encryptBlock:function(b,c){this._des1.encryptBlock(b,c);this._des2.decryptBlock(b,c);this._des3.encryptBlock(b,c)},decryptBlock:function(b,c){this._des3.decryptBlock(b,c);this._des2.encryptBlock(b,c);this._des1.decryptBlock(b,c)},keySize:6,ivSize:2,blockSize:2});h.TripleDES=e._createHelper(g)})(); +/* +CryptoJS v3.1.2 enc-base64.js +code.google.com/p/crypto-js +(c) 2009-2013 by Jeff Mott. All rights reserved. +code.google.com/p/crypto-js/wiki/License +*/ +(function(){var h=CryptoJS,j=h.lib.WordArray;h.enc.Base64={stringify:function(b){var e=b.words,f=b.sigBytes,c=this._map;b.clamp();b=[];for(var a=0;a>>2]>>>24-8*(a%4)&255)<<16|(e[a+1>>>2]>>>24-8*((a+1)%4)&255)<<8|e[a+2>>>2]>>>24-8*((a+2)%4)&255,g=0;4>g&&a+0.75*g>>6*(3-g)&63));if(e=c.charAt(64))for(;b.length%4;)b.push(e);return b.join("")},parse:function(b){var e=b.length,f=this._map,c=f.charAt(64);c&&(c=b.indexOf(c),-1!=c&&(e=c));for(var c=[],a=0,d=0;d< +e;d++)if(d%4){var g=f.indexOf(b.charAt(d-1))<<2*(d%4),h=f.indexOf(b.charAt(d))>>>6-2*(d%4);c[a>>>2]|=(g|h)<<24-8*(a%4);a++}return j.create(c,a)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="}})(); +/* +CryptoJS v3.1.2 md5.js +code.google.com/p/crypto-js +(c) 2009-2013 by Jeff Mott. All rights reserved. +code.google.com/p/crypto-js/wiki/License +*/ +(function(E){function h(a,f,g,j,p,h,k){a=a+(f&g|~f&j)+p+k;return(a<>>32-h)+f}function k(a,f,g,j,p,h,k){a=a+(f&j|g&~j)+p+k;return(a<>>32-h)+f}function l(a,f,g,j,h,k,l){a=a+(f^g^j)+h+l;return(a<>>32-k)+f}function n(a,f,g,j,h,k,l){a=a+(g^(f|~j))+h+l;return(a<>>32-k)+f}for(var r=CryptoJS,q=r.lib,F=q.WordArray,s=q.Hasher,q=r.algo,a=[],t=0;64>t;t++)a[t]=4294967296*E.abs(E.sin(t+1))|0;q=q.MD5=s.extend({_doReset:function(){this._hash=new F.init([1732584193,4023233417,2562383102,271733878])}, +_doProcessBlock:function(m,f){for(var g=0;16>g;g++){var j=f+g,p=m[j];m[j]=(p<<8|p>>>24)&16711935|(p<<24|p>>>8)&4278255360}var g=this._hash.words,j=m[f+0],p=m[f+1],q=m[f+2],r=m[f+3],s=m[f+4],t=m[f+5],u=m[f+6],v=m[f+7],w=m[f+8],x=m[f+9],y=m[f+10],z=m[f+11],A=m[f+12],B=m[f+13],C=m[f+14],D=m[f+15],b=g[0],c=g[1],d=g[2],e=g[3],b=h(b,c,d,e,j,7,a[0]),e=h(e,b,c,d,p,12,a[1]),d=h(d,e,b,c,q,17,a[2]),c=h(c,d,e,b,r,22,a[3]),b=h(b,c,d,e,s,7,a[4]),e=h(e,b,c,d,t,12,a[5]),d=h(d,e,b,c,u,17,a[6]),c=h(c,d,e,b,v,22,a[7]), +b=h(b,c,d,e,w,7,a[8]),e=h(e,b,c,d,x,12,a[9]),d=h(d,e,b,c,y,17,a[10]),c=h(c,d,e,b,z,22,a[11]),b=h(b,c,d,e,A,7,a[12]),e=h(e,b,c,d,B,12,a[13]),d=h(d,e,b,c,C,17,a[14]),c=h(c,d,e,b,D,22,a[15]),b=k(b,c,d,e,p,5,a[16]),e=k(e,b,c,d,u,9,a[17]),d=k(d,e,b,c,z,14,a[18]),c=k(c,d,e,b,j,20,a[19]),b=k(b,c,d,e,t,5,a[20]),e=k(e,b,c,d,y,9,a[21]),d=k(d,e,b,c,D,14,a[22]),c=k(c,d,e,b,s,20,a[23]),b=k(b,c,d,e,x,5,a[24]),e=k(e,b,c,d,C,9,a[25]),d=k(d,e,b,c,r,14,a[26]),c=k(c,d,e,b,w,20,a[27]),b=k(b,c,d,e,B,5,a[28]),e=k(e,b, +c,d,q,9,a[29]),d=k(d,e,b,c,v,14,a[30]),c=k(c,d,e,b,A,20,a[31]),b=l(b,c,d,e,t,4,a[32]),e=l(e,b,c,d,w,11,a[33]),d=l(d,e,b,c,z,16,a[34]),c=l(c,d,e,b,C,23,a[35]),b=l(b,c,d,e,p,4,a[36]),e=l(e,b,c,d,s,11,a[37]),d=l(d,e,b,c,v,16,a[38]),c=l(c,d,e,b,y,23,a[39]),b=l(b,c,d,e,B,4,a[40]),e=l(e,b,c,d,j,11,a[41]),d=l(d,e,b,c,r,16,a[42]),c=l(c,d,e,b,u,23,a[43]),b=l(b,c,d,e,x,4,a[44]),e=l(e,b,c,d,A,11,a[45]),d=l(d,e,b,c,D,16,a[46]),c=l(c,d,e,b,q,23,a[47]),b=n(b,c,d,e,j,6,a[48]),e=n(e,b,c,d,v,10,a[49]),d=n(d,e,b,c, +C,15,a[50]),c=n(c,d,e,b,t,21,a[51]),b=n(b,c,d,e,A,6,a[52]),e=n(e,b,c,d,r,10,a[53]),d=n(d,e,b,c,y,15,a[54]),c=n(c,d,e,b,p,21,a[55]),b=n(b,c,d,e,w,6,a[56]),e=n(e,b,c,d,D,10,a[57]),d=n(d,e,b,c,u,15,a[58]),c=n(c,d,e,b,B,21,a[59]),b=n(b,c,d,e,s,6,a[60]),e=n(e,b,c,d,z,10,a[61]),d=n(d,e,b,c,q,15,a[62]),c=n(c,d,e,b,x,21,a[63]);g[0]=g[0]+b|0;g[1]=g[1]+c|0;g[2]=g[2]+d|0;g[3]=g[3]+e|0},_doFinalize:function(){var a=this._data,f=a.words,g=8*this._nDataBytes,j=8*a.sigBytes;f[j>>>5]|=128<<24-j%32;var h=E.floor(g/ +4294967296);f[(j+64>>>9<<4)+15]=(h<<8|h>>>24)&16711935|(h<<24|h>>>8)&4278255360;f[(j+64>>>9<<4)+14]=(g<<8|g>>>24)&16711935|(g<<24|g>>>8)&4278255360;a.sigBytes=4*(f.length+1);this._process();a=this._hash;f=a.words;for(g=0;4>g;g++)j=f[g],f[g]=(j<<8|j>>>24)&16711935|(j<<24|j>>>8)&4278255360;return a},clone:function(){var a=s.clone.call(this);a._hash=this._hash.clone();return a}});r.MD5=s._createHelper(q);r.HmacMD5=s._createHmacHelper(q)})(Math); +/* +CryptoJS v3.1.2 sha1-min.js +code.google.com/p/crypto-js +(c) 2009-2013 by Jeff Mott. All rights reserved. +code.google.com/p/crypto-js/wiki/License +*/ +(function(){var k=CryptoJS,b=k.lib,m=b.WordArray,l=b.Hasher,d=[],b=k.algo.SHA1=l.extend({_doReset:function(){this._hash=new m.init([1732584193,4023233417,2562383102,271733878,3285377520])},_doProcessBlock:function(n,p){for(var a=this._hash.words,e=a[0],f=a[1],h=a[2],j=a[3],b=a[4],c=0;80>c;c++){if(16>c)d[c]=n[p+c]|0;else{var g=d[c-3]^d[c-8]^d[c-14]^d[c-16];d[c]=g<<1|g>>>31}g=(e<<5|e>>>27)+b+d[c];g=20>c?g+((f&h|~f&j)+1518500249):40>c?g+((f^h^j)+1859775393):60>c?g+((f&h|f&j|h&j)-1894007588):g+((f^h^ +j)-899497514);b=j;j=h;h=f<<30|f>>>2;f=e;e=g}a[0]=a[0]+e|0;a[1]=a[1]+f|0;a[2]=a[2]+h|0;a[3]=a[3]+j|0;a[4]=a[4]+b|0},_doFinalize:function(){var b=this._data,d=b.words,a=8*this._nDataBytes,e=8*b.sigBytes;d[e>>>5]|=128<<24-e%32;d[(e+64>>>9<<4)+14]=Math.floor(a/4294967296);d[(e+64>>>9<<4)+15]=a;b.sigBytes=4*d.length;this._process();return this._hash},clone:function(){var b=l.clone.call(this);b._hash=this._hash.clone();return b}});k.SHA1=l._createHelper(b);k.HmacSHA1=l._createHmacHelper(b)})(); +/* +CryptoJS v3.1.2 sha256-min.js +code.google.com/p/crypto-js +(c) 2009-2013 by Jeff Mott. All rights reserved. +code.google.com/p/crypto-js/wiki/License +*/ +(function(k){for(var g=CryptoJS,h=g.lib,v=h.WordArray,j=h.Hasher,h=g.algo,s=[],t=[],u=function(q){return 4294967296*(q-(q|0))|0},l=2,b=0;64>b;){var d;a:{d=l;for(var w=k.sqrt(d),r=2;r<=w;r++)if(!(d%r)){d=!1;break a}d=!0}d&&(8>b&&(s[b]=u(k.pow(l,0.5))),t[b]=u(k.pow(l,1/3)),b++);l++}var n=[],h=h.SHA256=j.extend({_doReset:function(){this._hash=new v.init(s.slice(0))},_doProcessBlock:function(q,h){for(var a=this._hash.words,c=a[0],d=a[1],b=a[2],k=a[3],f=a[4],g=a[5],j=a[6],l=a[7],e=0;64>e;e++){if(16>e)n[e]= +q[h+e]|0;else{var m=n[e-15],p=n[e-2];n[e]=((m<<25|m>>>7)^(m<<14|m>>>18)^m>>>3)+n[e-7]+((p<<15|p>>>17)^(p<<13|p>>>19)^p>>>10)+n[e-16]}m=l+((f<<26|f>>>6)^(f<<21|f>>>11)^(f<<7|f>>>25))+(f&g^~f&j)+t[e]+n[e];p=((c<<30|c>>>2)^(c<<19|c>>>13)^(c<<10|c>>>22))+(c&d^c&b^d&b);l=j;j=g;g=f;f=k+m|0;k=b;b=d;d=c;c=m+p|0}a[0]=a[0]+c|0;a[1]=a[1]+d|0;a[2]=a[2]+b|0;a[3]=a[3]+k|0;a[4]=a[4]+f|0;a[5]=a[5]+g|0;a[6]=a[6]+j|0;a[7]=a[7]+l|0},_doFinalize:function(){var d=this._data,b=d.words,a=8*this._nDataBytes,c=8*d.sigBytes; +b[c>>>5]|=128<<24-c%32;b[(c+64>>>9<<4)+14]=k.floor(a/4294967296);b[(c+64>>>9<<4)+15]=a;d.sigBytes=4*b.length;this._process();return this._hash},clone:function(){var b=j.clone.call(this);b._hash=this._hash.clone();return b}});g.SHA256=j._createHelper(h);g.HmacSHA256=j._createHmacHelper(h)})(Math); +/* +CryptoJS v3.1.2 sha224-min.js +code.google.com/p/crypto-js +(c) 2009-2013 by Jeff Mott. All rights reserved. +code.google.com/p/crypto-js/wiki/License +*/ +(function(){var b=CryptoJS,d=b.lib.WordArray,a=b.algo,c=a.SHA256,a=a.SHA224=c.extend({_doReset:function(){this._hash=new d.init([3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428])},_doFinalize:function(){var a=c._doFinalize.call(this);a.sigBytes-=4;return a}});b.SHA224=c._createHelper(a);b.HmacSHA224=c._createHmacHelper(a)})(); +/* +CryptoJS v3.1.2 sha512-min.js +code.google.com/p/crypto-js +(c) 2009-2013 by Jeff Mott. All rights reserved. +code.google.com/p/crypto-js/wiki/License +*/ +(function(){function a(){return d.create.apply(d,arguments)}for(var n=CryptoJS,r=n.lib.Hasher,e=n.x64,d=e.Word,T=e.WordArray,e=n.algo,ea=[a(1116352408,3609767458),a(1899447441,602891725),a(3049323471,3964484399),a(3921009573,2173295548),a(961987163,4081628472),a(1508970993,3053834265),a(2453635748,2937671579),a(2870763221,3664609560),a(3624381080,2734883394),a(310598401,1164996542),a(607225278,1323610764),a(1426881987,3590304994),a(1925078388,4068182383),a(2162078206,991336113),a(2614888103,633803317), +a(3248222580,3479774868),a(3835390401,2666613458),a(4022224774,944711139),a(264347078,2341262773),a(604807628,2007800933),a(770255983,1495990901),a(1249150122,1856431235),a(1555081692,3175218132),a(1996064986,2198950837),a(2554220882,3999719339),a(2821834349,766784016),a(2952996808,2566594879),a(3210313671,3203337956),a(3336571891,1034457026),a(3584528711,2466948901),a(113926993,3758326383),a(338241895,168717936),a(666307205,1188179964),a(773529912,1546045734),a(1294757372,1522805485),a(1396182291, +2643833823),a(1695183700,2343527390),a(1986661051,1014477480),a(2177026350,1206759142),a(2456956037,344077627),a(2730485921,1290863460),a(2820302411,3158454273),a(3259730800,3505952657),a(3345764771,106217008),a(3516065817,3606008344),a(3600352804,1432725776),a(4094571909,1467031594),a(275423344,851169720),a(430227734,3100823752),a(506948616,1363258195),a(659060556,3750685593),a(883997877,3785050280),a(958139571,3318307427),a(1322822218,3812723403),a(1537002063,2003034995),a(1747873779,3602036899), +a(1955562222,1575990012),a(2024104815,1125592928),a(2227730452,2716904306),a(2361852424,442776044),a(2428436474,593698344),a(2756734187,3733110249),a(3204031479,2999351573),a(3329325298,3815920427),a(3391569614,3928383900),a(3515267271,566280711),a(3940187606,3454069534),a(4118630271,4000239992),a(116418474,1914138554),a(174292421,2731055270),a(289380356,3203993006),a(460393269,320620315),a(685471733,587496836),a(852142971,1086792851),a(1017036298,365543100),a(1126000580,2618297676),a(1288033470, +3409855158),a(1501505948,4234509866),a(1607167915,987167468),a(1816402316,1246189591)],v=[],w=0;80>w;w++)v[w]=a();e=e.SHA512=r.extend({_doReset:function(){this._hash=new T.init([new d.init(1779033703,4089235720),new d.init(3144134277,2227873595),new d.init(1013904242,4271175723),new d.init(2773480762,1595750129),new d.init(1359893119,2917565137),new d.init(2600822924,725511199),new d.init(528734635,4215389547),new d.init(1541459225,327033209)])},_doProcessBlock:function(a,d){for(var f=this._hash.words, +F=f[0],e=f[1],n=f[2],r=f[3],G=f[4],H=f[5],I=f[6],f=f[7],w=F.high,J=F.low,X=e.high,K=e.low,Y=n.high,L=n.low,Z=r.high,M=r.low,$=G.high,N=G.low,aa=H.high,O=H.low,ba=I.high,P=I.low,ca=f.high,Q=f.low,k=w,g=J,z=X,x=K,A=Y,y=L,U=Z,B=M,l=$,h=N,R=aa,C=O,S=ba,D=P,V=ca,E=Q,m=0;80>m;m++){var s=v[m];if(16>m)var j=s.high=a[d+2*m]|0,b=s.low=a[d+2*m+1]|0;else{var j=v[m-15],b=j.high,p=j.low,j=(b>>>1|p<<31)^(b>>>8|p<<24)^b>>>7,p=(p>>>1|b<<31)^(p>>>8|b<<24)^(p>>>7|b<<25),u=v[m-2],b=u.high,c=u.low,u=(b>>>19|c<<13)^(b<< +3|c>>>29)^b>>>6,c=(c>>>19|b<<13)^(c<<3|b>>>29)^(c>>>6|b<<26),b=v[m-7],W=b.high,t=v[m-16],q=t.high,t=t.low,b=p+b.low,j=j+W+(b>>>0

>>0?1:0),b=b+c,j=j+u+(b>>>0>>0?1:0),b=b+t,j=j+q+(b>>>0>>0?1:0);s.high=j;s.low=b}var W=l&R^~l&S,t=h&C^~h&D,s=k&z^k&A^z&A,T=g&x^g&y^x&y,p=(k>>>28|g<<4)^(k<<30|g>>>2)^(k<<25|g>>>7),u=(g>>>28|k<<4)^(g<<30|k>>>2)^(g<<25|k>>>7),c=ea[m],fa=c.high,da=c.low,c=E+((h>>>14|l<<18)^(h>>>18|l<<14)^(h<<23|l>>>9)),q=V+((l>>>14|h<<18)^(l>>>18|h<<14)^(l<<23|h>>>9))+(c>>>0>>0?1: +0),c=c+t,q=q+W+(c>>>0>>0?1:0),c=c+da,q=q+fa+(c>>>0>>0?1:0),c=c+b,q=q+j+(c>>>0>>0?1:0),b=u+T,s=p+s+(b>>>0>>0?1:0),V=S,E=D,S=R,D=C,R=l,C=h,h=B+c|0,l=U+q+(h>>>0>>0?1:0)|0,U=A,B=y,A=z,y=x,z=k,x=g,g=c+b|0,k=q+s+(g>>>0>>0?1:0)|0}J=F.low=J+g;F.high=w+k+(J>>>0>>0?1:0);K=e.low=K+x;e.high=X+z+(K>>>0>>0?1:0);L=n.low=L+y;n.high=Y+A+(L>>>0>>0?1:0);M=r.low=M+B;r.high=Z+U+(M>>>0>>0?1:0);N=G.low=N+h;G.high=$+l+(N>>>0>>0?1:0);O=H.low=O+C;H.high=aa+R+(O>>>0>>0?1:0);P=I.low=P+D; +I.high=ba+S+(P>>>0>>0?1:0);Q=f.low=Q+E;f.high=ca+V+(Q>>>0>>0?1:0)},_doFinalize:function(){var a=this._data,d=a.words,f=8*this._nDataBytes,e=8*a.sigBytes;d[e>>>5]|=128<<24-e%32;d[(e+128>>>10<<5)+30]=Math.floor(f/4294967296);d[(e+128>>>10<<5)+31]=f;a.sigBytes=4*d.length;this._process();return this._hash.toX32()},clone:function(){var a=r.clone.call(this);a._hash=this._hash.clone();return a},blockSize:32});n.SHA512=r._createHelper(e);n.HmacSHA512=r._createHmacHelper(e)})(); +/* +CryptoJS v3.1.2 sha384-min.js +code.google.com/p/crypto-js +(c) 2009-2013 by Jeff Mott. All rights reserved. +code.google.com/p/crypto-js/wiki/License +*/ +(function(){var c=CryptoJS,a=c.x64,b=a.Word,e=a.WordArray,a=c.algo,d=a.SHA512,a=a.SHA384=d.extend({_doReset:function(){this._hash=new e.init([new b.init(3418070365,3238371032),new b.init(1654270250,914150663),new b.init(2438529370,812702999),new b.init(355462360,4144912697),new b.init(1731405415,4290775857),new b.init(2394180231,1750603025),new b.init(3675008525,1694076839),new b.init(1203062813,3204075428)])},_doFinalize:function(){var a=d._doFinalize.call(this);a.sigBytes-=16;return a}});c.SHA384= +d._createHelper(a);c.HmacSHA384=d._createHmacHelper(a)})(); +/* +CryptoJS v3.1.2 ripemd160-min.js +code.google.com/p/crypto-js +(c) 2009-2013 by Jeff Mott. All rights reserved. +code.google.com/p/crypto-js/wiki/License +*/ +/* +(c) 2012 by Cedric Mesnil. All rights reserved. +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +(function(){var q=CryptoJS,d=q.lib,n=d.WordArray,p=d.Hasher,d=q.algo,x=n.create([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8,3,10,14,4,9,15,8,1,2,7,0,6,13,11,5,12,1,9,11,10,0,8,12,4,13,3,7,15,14,5,6,2,4,0,5,9,7,12,2,10,14,1,3,8,11,6,15,13]),y=n.create([5,14,7,0,9,2,11,4,13,6,15,8,1,10,3,12,6,11,3,7,0,13,5,10,14,15,8,12,4,9,1,2,15,5,1,3,7,14,6,9,11,8,12,2,10,0,4,13,8,6,4,1,3,11,15,0,5,12,2,13,9,7,10,14,12,15,10,4,1,5,8,7,6,2,13,14,0,3,9,11]),z=n.create([11,14,15,12, +5,8,7,9,11,13,14,15,6,7,9,8,7,6,8,13,11,9,7,15,7,12,15,9,11,7,13,12,11,13,6,7,14,9,13,15,14,8,13,6,5,12,7,5,11,12,14,15,14,15,9,8,9,14,5,6,8,6,5,12,9,15,5,11,6,8,13,12,5,12,13,14,11,8,5,6]),A=n.create([8,9,9,11,13,15,15,5,7,7,8,11,14,14,12,6,9,13,15,7,12,8,9,11,7,7,12,7,6,15,13,11,9,7,15,11,8,6,6,14,12,13,5,14,13,13,7,5,15,5,8,11,14,14,6,14,6,9,12,9,12,5,15,8,8,5,12,9,12,5,14,6,8,13,6,5,15,13,11,11]),B=n.create([0,1518500249,1859775393,2400959708,2840853838]),C=n.create([1352829926,1548603684,1836072691, +2053994217,0]),d=d.RIPEMD160=p.extend({_doReset:function(){this._hash=n.create([1732584193,4023233417,2562383102,271733878,3285377520])},_doProcessBlock:function(e,v){for(var b=0;16>b;b++){var c=v+b,f=e[c];e[c]=(f<<8|f>>>24)&16711935|(f<<24|f>>>8)&4278255360}var c=this._hash.words,f=B.words,d=C.words,n=x.words,q=y.words,p=z.words,w=A.words,t,g,h,j,r,u,k,l,m,s;u=t=c[0];k=g=c[1];l=h=c[2];m=j=c[3];s=r=c[4];for(var a,b=0;80>b;b+=1)a=t+e[v+n[b]]|0,a=16>b?a+((g^h^j)+f[0]):32>b?a+((g&h|~g&j)+f[1]):48>b? +a+(((g|~h)^j)+f[2]):64>b?a+((g&j|h&~j)+f[3]):a+((g^(h|~j))+f[4]),a|=0,a=a<>>32-p[b],a=a+r|0,t=r,r=j,j=h<<10|h>>>22,h=g,g=a,a=u+e[v+q[b]]|0,a=16>b?a+((k^(l|~m))+d[0]):32>b?a+((k&m|l&~m)+d[1]):48>b?a+(((k|~l)^m)+d[2]):64>b?a+((k&l|~k&m)+d[3]):a+((k^l^m)+d[4]),a|=0,a=a<>>32-w[b],a=a+s|0,u=s,s=m,m=l<<10|l>>>22,l=k,k=a;a=c[1]+h+m|0;c[1]=c[2]+j+s|0;c[2]=c[3]+r+u|0;c[3]=c[4]+t+k|0;c[4]=c[0]+g+l|0;c[0]=a},_doFinalize:function(){var e=this._data,d=e.words,b=8*this._nDataBytes,c=8*e.sigBytes; +d[c>>>5]|=128<<24-c%32;d[(c+64>>>9<<4)+14]=(b<<8|b>>>24)&16711935|(b<<24|b>>>8)&4278255360;e.sigBytes=4*(d.length+1);this._process();e=this._hash;d=e.words;for(b=0;5>b;b++)c=d[b],d[b]=(c<<8|c>>>24)&16711935|(c<<24|c>>>8)&4278255360;return e},clone:function(){var d=p.clone.call(this);d._hash=this._hash.clone();return d}});q.RIPEMD160=p._createHelper(d);q.HmacRIPEMD160=p._createHmacHelper(d)})(Math); +/* +CryptoJS v3.1.2 hmac.js +code.google.com/p/crypto-js +(c) 2009-2013 by Jeff Mott. All rights reserved. +code.google.com/p/crypto-js/wiki/License +*/ +(function(){var c=CryptoJS,k=c.enc.Utf8;c.algo.HMAC=c.lib.Base.extend({init:function(a,b){a=this._hasher=new a.init;"string"==typeof b&&(b=k.parse(b));var c=a.blockSize,e=4*c;b.sigBytes>e&&(b=a.finalize(b));b.clamp();for(var f=this._oKey=b.clone(),g=this._iKey=b.clone(),h=f.words,j=g.words,d=0;d>6)+b64map.charAt(e&63)}if(b+1==d.length){e=parseInt(d.substring(b,b+1),16);a+=b64map.charAt(e<<2)}else{if(b+2==d.length){e=parseInt(d.substring(b,b+2),16);a+=b64map.charAt(e>>2)+b64map.charAt((e&3)<<4)}}if(b64pad){while((a.length&3)>0){a+=b64pad}}return a}function b64tohex(f){var d="";var e;var b=0;var c;var a;for(e=0;e>2);c=a&3;b=1}else{if(b==1){d+=int2char((c<<2)|(a>>4));c=a&15;b=2}else{if(b==2){d+=int2char(c);d+=int2char(a>>2);c=a&3;b=3}else{d+=int2char((c<<2)|(a>>4));d+=int2char(a&15);b=0}}}}if(b==1){d+=int2char(c<<2)}return d}function b64toBA(e){var d=b64tohex(e);var c;var b=new Array();for(c=0;2*c=0){var d=a*this[f++]+b[e]+h;h=Math.floor(d/67108864);b[e++]=d&67108863}return h}function am2(f,q,r,e,o,a){var k=q&32767,p=q>>15;while(--a>=0){var d=this[f]&32767;var g=this[f++]>>15;var b=p*d+g*k;d=k*d+((b&32767)<<15)+r[e]+(o&1073741823);o=(d>>>30)+(b>>>15)+p*g+(o>>>30);r[e++]=d&1073741823}return o}function am3(f,q,r,e,o,a){var k=q&16383,p=q>>14;while(--a>=0){var d=this[f]&16383;var g=this[f++]>>14;var b=p*d+g*k;d=k*d+((b&16383)<<14)+r[e]+o;o=(d>>28)+(b>>14)+p*g;r[e++]=d&268435455}return o}if(j_lm&&(navigator.appName=="Microsoft Internet Explorer")){BigInteger.prototype.am=am2;dbits=30}else{if(j_lm&&(navigator.appName!="Netscape")){BigInteger.prototype.am=am1;dbits=26}else{BigInteger.prototype.am=am3;dbits=28}}BigInteger.prototype.DB=dbits;BigInteger.prototype.DM=((1<=0;--a){b[a]=this[a]}b.t=this.t;b.s=this.s}function bnpFromInt(a){this.t=1;this.s=(a<0)?-1:0;if(a>0){this[0]=a}else{if(a<-1){this[0]=a+this.DV}else{this.t=0}}}function nbv(a){var b=nbi();b.fromInt(a);return b}function bnpFromString(h,c){var e;if(c==16){e=4}else{if(c==8){e=3}else{if(c==256){e=8}else{if(c==2){e=1}else{if(c==32){e=5}else{if(c==4){e=2}else{this.fromRadix(h,c);return}}}}}}this.t=0;this.s=0;var g=h.length,d=false,f=0;while(--g>=0){var a=(e==8)?h[g]&255:intAt(h,g);if(a<0){if(h.charAt(g)=="-"){d=true}continue}d=false;if(f==0){this[this.t++]=a}else{if(f+e>this.DB){this[this.t-1]|=(a&((1<<(this.DB-f))-1))<>(this.DB-f))}else{this[this.t-1]|=a<=this.DB){f-=this.DB}}if(e==8&&(h[0]&128)!=0){this.s=-1;if(f>0){this[this.t-1]|=((1<<(this.DB-f))-1)<0&&this[this.t-1]==a){--this.t}}function bnToString(c){if(this.s<0){return"-"+this.negate().toString(c)}var e;if(c==16){e=4}else{if(c==8){e=3}else{if(c==2){e=1}else{if(c==32){e=5}else{if(c==4){e=2}else{return this.toRadix(c)}}}}}var g=(1<0){if(j>j)>0){a=true;h=int2char(l)}while(f>=0){if(j>(j+=this.DB-e)}else{l=(this[f]>>(j-=e))&g;if(j<=0){j+=this.DB;--f}}if(l>0){a=true}if(a){h+=int2char(l)}}}return a?h:"0"}function bnNegate(){var a=nbi();BigInteger.ZERO.subTo(this,a);return a}function bnAbs(){return(this.s<0)?this.negate():this}function bnCompareTo(b){var d=this.s-b.s;if(d!=0){return d}var c=this.t;d=c-b.t;if(d!=0){return(this.s<0)?-d:d}while(--c>=0){if((d=this[c]-b[c])!=0){return d}}return 0}function nbits(a){var c=1,b;if((b=a>>>16)!=0){a=b;c+=16}if((b=a>>8)!=0){a=b;c+=8}if((b=a>>4)!=0){a=b;c+=4}if((b=a>>2)!=0){a=b;c+=2}if((b=a>>1)!=0){a=b;c+=1}return c}function bnBitLength(){if(this.t<=0){return 0}return this.DB*(this.t-1)+nbits(this[this.t-1]^(this.s&this.DM))}function bnpDLShiftTo(c,b){var a;for(a=this.t-1;a>=0;--a){b[a+c]=this[a]}for(a=c-1;a>=0;--a){b[a]=0}b.t=this.t+c;b.s=this.s}function bnpDRShiftTo(c,b){for(var a=c;a=0;--d){e[d+f+1]=(this[d]>>a)|h;h=(this[d]&g)<=0;--d){e[d]=0}e[f]=h;e.t=this.t+f+1;e.s=this.s;e.clamp()}function bnpRShiftTo(g,d){d.s=this.s;var e=Math.floor(g/this.DB);if(e>=this.t){d.t=0;return}var b=g%this.DB;var a=this.DB-b;var f=(1<>b;for(var c=e+1;c>b}if(b>0){d[this.t-e-1]|=(this.s&f)<>=this.DB}if(d.t>=this.DB}g+=this.s}else{g+=this.s;while(e>=this.DB}g-=d.s}f.s=(g<0)?-1:0;if(g<-1){f[e++]=this.DV+g}else{if(g>0){f[e++]=g}}f.t=e;f.clamp()}function bnpMultiplyTo(c,e){var b=this.abs(),f=c.abs();var d=b.t;e.t=d+f.t;while(--d>=0){e[d]=0}for(d=0;d=0){d[b]=0}for(b=0;b=a.DV){d[b+a.t]-=a.DV;d[b+a.t+1]=1}}if(d.t>0){d[d.t-1]+=a.am(b,a[b],d,2*b,0,1)}d.s=0;d.clamp()}function bnpDivRemTo(n,h,g){var w=n.abs();if(w.t<=0){return}var k=this.abs();if(k.t0){w.lShiftTo(v,d);k.lShiftTo(v,g)}else{w.copyTo(d);k.copyTo(g)}var p=d.t;var b=d[p-1];if(b==0){return}var o=b*(1<1)?d[p-2]>>this.F2:0);var A=this.FV/o,z=(1<=0){g[g.t++]=1;g.subTo(f,g)}BigInteger.ONE.dlShiftTo(p,f);f.subTo(d,d);while(d.t=0){var c=(g[--u]==b)?this.DM:Math.floor(g[u]*A+(g[u-1]+x)*z);if((g[u]+=d.am(0,c,g,s,0,p))0){g.rShiftTo(v,g)}if(a<0){BigInteger.ZERO.subTo(g,g)}}function bnMod(b){var c=nbi();this.abs().divRemTo(b,null,c);if(this.s<0&&c.compareTo(BigInteger.ZERO)>0){b.subTo(c,c)}return c}function Classic(a){this.m=a}function cConvert(a){if(a.s<0||a.compareTo(this.m)>=0){return a.mod(this.m)}else{return a}}function cRevert(a){return a}function cReduce(a){a.divRemTo(this.m,null,a)}function cMulTo(a,c,b){a.multiplyTo(c,b);this.reduce(b)}function cSqrTo(a,b){a.squareTo(b);this.reduce(b)}Classic.prototype.convert=cConvert;Classic.prototype.revert=cRevert;Classic.prototype.reduce=cReduce;Classic.prototype.mulTo=cMulTo;Classic.prototype.sqrTo=cSqrTo;function bnpInvDigit(){if(this.t<1){return 0}var a=this[0];if((a&1)==0){return 0}var b=a&3;b=(b*(2-(a&15)*b))&15;b=(b*(2-(a&255)*b))&255;b=(b*(2-(((a&65535)*b)&65535)))&65535;b=(b*(2-a*b%this.DV))%this.DV;return(b>0)?this.DV-b:-b}function Montgomery(a){this.m=a;this.mp=a.invDigit();this.mpl=this.mp&32767;this.mph=this.mp>>15;this.um=(1<<(a.DB-15))-1;this.mt2=2*a.t}function montConvert(a){var b=nbi();a.abs().dlShiftTo(this.m.t,b);b.divRemTo(this.m,null,b);if(a.s<0&&b.compareTo(BigInteger.ZERO)>0){this.m.subTo(b,b)}return b}function montRevert(a){var b=nbi();a.copyTo(b);this.reduce(b);return b}function montReduce(a){while(a.t<=this.mt2){a[a.t++]=0}for(var c=0;c>15)*this.mpl)&this.um)<<15))&a.DM;b=c+this.m.t;a[b]+=this.m.am(0,d,a,c,0,this.m.t);while(a[b]>=a.DV){a[b]-=a.DV;a[++b]++}}a.clamp();a.drShiftTo(this.m.t,a);if(a.compareTo(this.m)>=0){a.subTo(this.m,a)}}function montSqrTo(a,b){a.squareTo(b);this.reduce(b)}function montMulTo(a,c,b){a.multiplyTo(c,b);this.reduce(b)}Montgomery.prototype.convert=montConvert;Montgomery.prototype.revert=montRevert;Montgomery.prototype.reduce=montReduce;Montgomery.prototype.mulTo=montMulTo;Montgomery.prototype.sqrTo=montSqrTo;function bnpIsEven(){return((this.t>0)?(this[0]&1):this.s)==0}function bnpExp(h,j){if(h>4294967295||h<1){return BigInteger.ONE}var f=nbi(),a=nbi(),d=j.convert(this),c=nbits(h)-1;d.copyTo(f);while(--c>=0){j.sqrTo(f,a);if((h&(1<0){j.mulTo(a,d,f)}else{var b=f;f=a;a=b}}return j.revert(f)}function bnModPowInt(b,a){var c;if(b<256||a.isEven()){c=new Classic(a)}else{c=new Montgomery(a)}return this.exp(b,c)}BigInteger.prototype.copyTo=bnpCopyTo;BigInteger.prototype.fromInt=bnpFromInt;BigInteger.prototype.fromString=bnpFromString;BigInteger.prototype.clamp=bnpClamp;BigInteger.prototype.dlShiftTo=bnpDLShiftTo;BigInteger.prototype.drShiftTo=bnpDRShiftTo;BigInteger.prototype.lShiftTo=bnpLShiftTo;BigInteger.prototype.rShiftTo=bnpRShiftTo;BigInteger.prototype.subTo=bnpSubTo;BigInteger.prototype.multiplyTo=bnpMultiplyTo;BigInteger.prototype.squareTo=bnpSquareTo;BigInteger.prototype.divRemTo=bnpDivRemTo;BigInteger.prototype.invDigit=bnpInvDigit;BigInteger.prototype.isEven=bnpIsEven;BigInteger.prototype.exp=bnpExp;BigInteger.prototype.toString=bnToString;BigInteger.prototype.negate=bnNegate;BigInteger.prototype.abs=bnAbs;BigInteger.prototype.compareTo=bnCompareTo;BigInteger.prototype.bitLength=bnBitLength;BigInteger.prototype.mod=bnMod;BigInteger.prototype.modPowInt=bnModPowInt;BigInteger.ZERO=nbv(0);BigInteger.ONE=nbv(1); +/*! (c) Tom Wu | http://www-cs-students.stanford.edu/~tjw/jsbn/ + */ +function bnClone(){var a=nbi();this.copyTo(a);return a}function bnIntValue(){if(this.s<0){if(this.t==1){return this[0]-this.DV}else{if(this.t==0){return -1}}}else{if(this.t==1){return this[0]}else{if(this.t==0){return 0}}}return((this[1]&((1<<(32-this.DB))-1))<>24}function bnShortValue(){return(this.t==0)?this.s:(this[0]<<16)>>16}function bnpChunkSize(a){return Math.floor(Math.LN2*this.DB/Math.log(a))}function bnSigNum(){if(this.s<0){return -1}else{if(this.t<=0||(this.t==1&&this[0]<=0)){return 0}else{return 1}}}function bnpToRadix(c){if(c==null){c=10}if(this.signum()==0||c<2||c>36){return"0"}var f=this.chunkSize(c);var e=Math.pow(c,f);var i=nbv(e),j=nbi(),h=nbi(),g="";this.divRemTo(i,j,h);while(j.signum()>0){g=(e+h.intValue()).toString(c).substr(1)+g;j.divRemTo(i,j,h)}return h.intValue().toString(c)+g}function bnpFromRadix(m,h){this.fromInt(0);if(h==null){h=10}var f=this.chunkSize(h);var g=Math.pow(h,f),e=false,a=0,l=0;for(var c=0;c=f){this.dMultiply(g);this.dAddOffset(l,0);a=0;l=0}}if(a>0){this.dMultiply(Math.pow(h,a));this.dAddOffset(l,0)}if(e){BigInteger.ZERO.subTo(this,this)}}function bnpFromNumber(f,e,h){if("number"==typeof e){if(f<2){this.fromInt(1)}else{this.fromNumber(f,h);if(!this.testBit(f-1)){this.bitwiseTo(BigInteger.ONE.shiftLeft(f-1),op_or,this)}if(this.isEven()){this.dAddOffset(1,0)}while(!this.isProbablePrime(e)){this.dAddOffset(2,0);if(this.bitLength()>f){this.subTo(BigInteger.ONE.shiftLeft(f-1),this)}}}}else{var d=new Array(),g=f&7;d.length=(f>>3)+1;e.nextBytes(d);if(g>0){d[0]&=((1<0){if(e>e)!=(this.s&this.DM)>>e){c[a++]=f|(this.s<<(this.DB-e))}while(b>=0){if(e<8){f=(this[b]&((1<>(e+=this.DB-8)}else{f=(this[b]>>(e-=8))&255;if(e<=0){e+=this.DB;--b}}if((f&128)!=0){f|=-256}if(a==0&&(this.s&128)!=(f&128)){++a}if(a>0||f!=this.s){c[a++]=f}}}return c}function bnEquals(b){return(this.compareTo(b)==0)}function bnMin(b){return(this.compareTo(b)<0)?this:b}function bnMax(b){return(this.compareTo(b)>0)?this:b}function bnpBitwiseTo(c,h,e){var d,g,b=Math.min(c.t,this.t);for(d=0;d>=16;b+=16}if((a&255)==0){a>>=8;b+=8}if((a&15)==0){a>>=4;b+=4}if((a&3)==0){a>>=2;b+=2}if((a&1)==0){++b}return b}function bnGetLowestSetBit(){for(var a=0;a=this.t){return(this.s!=0)}return((this[a]&(1<<(b%this.DB)))!=0)}function bnpChangeBit(c,b){var a=BigInteger.ONE.shiftLeft(c);this.bitwiseTo(a,b,a);return a}function bnSetBit(a){return this.changeBit(a,op_or)}function bnClearBit(a){return this.changeBit(a,op_andnot)}function bnFlipBit(a){return this.changeBit(a,op_xor)}function bnpAddTo(d,f){var e=0,g=0,b=Math.min(d.t,this.t);while(e>=this.DB}if(d.t>=this.DB}g+=this.s}else{g+=this.s;while(e>=this.DB}g+=d.s}f.s=(g<0)?-1:0;if(g>0){f[e++]=g}else{if(g<-1){f[e++]=this.DV+g}}f.t=e;f.clamp()}function bnAdd(b){var c=nbi();this.addTo(b,c);return c}function bnSubtract(b){var c=nbi();this.subTo(b,c);return c}function bnMultiply(b){var c=nbi();this.multiplyTo(b,c);return c}function bnSquare(){var a=nbi();this.squareTo(a);return a}function bnDivide(b){var c=nbi();this.divRemTo(b,c,null);return c}function bnRemainder(b){var c=nbi();this.divRemTo(b,null,c);return c}function bnDivideAndRemainder(b){var d=nbi(),c=nbi();this.divRemTo(b,d,c);return new Array(d,c)}function bnpDMultiply(a){this[this.t]=this.am(0,a-1,this,0,0,this.t);++this.t;this.clamp()}function bnpDAddOffset(b,a){if(b==0){return}while(this.t<=a){this[this.t++]=0}this[a]+=b;while(this[a]>=this.DV){this[a]-=this.DV;if(++a>=this.t){this[this.t++]=0}++this[a]}}function NullExp(){}function nNop(a){return a}function nMulTo(a,c,b){a.multiplyTo(c,b)}function nSqrTo(a,b){a.squareTo(b)}NullExp.prototype.convert=nNop;NullExp.prototype.revert=nNop;NullExp.prototype.mulTo=nMulTo;NullExp.prototype.sqrTo=nSqrTo;function bnPow(a){return this.exp(a,new NullExp())}function bnpMultiplyLowerTo(b,f,e){var d=Math.min(this.t+b.t,f);e.s=0;e.t=d;while(d>0){e[--d]=0}var c;for(c=e.t-this.t;d=0){d[c]=0}for(c=Math.max(e-this.t,0);c2*this.m.t){return a.mod(this.m)}else{if(a.compareTo(this.m)<0){return a}else{var b=nbi();a.copyTo(b);this.reduce(b);return b}}}function barrettRevert(a){return a}function barrettReduce(a){a.drShiftTo(this.m.t-1,this.r2);if(a.t>this.m.t+1){a.t=this.m.t+1;a.clamp()}this.mu.multiplyUpperTo(this.r2,this.m.t+1,this.q3);this.m.multiplyLowerTo(this.q3,this.m.t+1,this.r2);while(a.compareTo(this.r2)<0){a.dAddOffset(1,this.m.t+1)}a.subTo(this.r2,a);while(a.compareTo(this.m)>=0){a.subTo(this.m,a)}}function barrettSqrTo(a,b){a.squareTo(b);this.reduce(b)}function barrettMulTo(a,c,b){a.multiplyTo(c,b);this.reduce(b)}Barrett.prototype.convert=barrettConvert;Barrett.prototype.revert=barrettRevert;Barrett.prototype.reduce=barrettReduce;Barrett.prototype.mulTo=barrettMulTo;Barrett.prototype.sqrTo=barrettSqrTo;function bnModPow(q,f){var o=q.bitLength(),h,b=nbv(1),v;if(o<=0){return b}else{if(o<18){h=1}else{if(o<48){h=3}else{if(o<144){h=4}else{if(o<768){h=5}else{h=6}}}}}if(o<8){v=new Classic(f)}else{if(f.isEven()){v=new Barrett(f)}else{v=new Montgomery(f)}}var p=new Array(),d=3,s=h-1,a=(1<1){var A=nbi();v.sqrTo(p[1],A);while(d<=a){p[d]=nbi();v.mulTo(A,p[d-2],p[d]);d+=2}}var l=q.t-1,x,u=true,c=nbi(),y;o=nbits(q[l])-1;while(l>=0){if(o>=s){x=(q[l]>>(o-s))&a}else{x=(q[l]&((1<<(o+1))-1))<<(s-o);if(l>0){x|=q[l-1]>>(this.DB+o-s)}}d=h;while((x&1)==0){x>>=1;--d}if((o-=d)<0){o+=this.DB;--l}if(u){p[x].copyTo(b);u=false}else{while(d>1){v.sqrTo(b,c);v.sqrTo(c,b);d-=2}if(d>0){v.sqrTo(b,c)}else{y=b;b=c;c=y}v.mulTo(c,p[x],b)}while(l>=0&&(q[l]&(1<0){b.rShiftTo(f,b);h.rShiftTo(f,h)}while(b.signum()>0){if((d=b.getLowestSetBit())>0){b.rShiftTo(d,b)}if((d=h.getLowestSetBit())>0){h.rShiftTo(d,h)}if(b.compareTo(h)>=0){b.subTo(h,b);b.rShiftTo(1,b)}else{h.subTo(b,h);h.rShiftTo(1,h)}}if(f>0){h.lShiftTo(f,h)}return h}function bnpModInt(e){if(e<=0){return 0}var c=this.DV%e,b=(this.s<0)?e-1:0;if(this.t>0){if(c==0){b=this[0]%e}else{for(var a=this.t-1;a>=0;--a){b=(c*b+this[a])%e}}}return b}function bnModInverse(f){var j=f.isEven();if((this.isEven()&&j)||f.signum()==0){return BigInteger.ZERO}var i=f.clone(),h=this.clone();var g=nbv(1),e=nbv(0),l=nbv(0),k=nbv(1);while(i.signum()!=0){while(i.isEven()){i.rShiftTo(1,i);if(j){if(!g.isEven()||!e.isEven()){g.addTo(this,g);e.subTo(f,e)}g.rShiftTo(1,g)}else{if(!e.isEven()){e.subTo(f,e)}}e.rShiftTo(1,e)}while(h.isEven()){h.rShiftTo(1,h);if(j){if(!l.isEven()||!k.isEven()){l.addTo(this,l);k.subTo(f,k)}l.rShiftTo(1,l)}else{if(!k.isEven()){k.subTo(f,k)}}k.rShiftTo(1,k)}if(i.compareTo(h)>=0){i.subTo(h,i);if(j){g.subTo(l,g)}e.subTo(k,e)}else{h.subTo(i,h);if(j){l.subTo(g,l)}k.subTo(e,k)}}if(h.compareTo(BigInteger.ONE)!=0){return BigInteger.ZERO}if(k.compareTo(f)>=0){return k.subtract(f)}if(k.signum()<0){k.addTo(f,k)}else{return k}if(k.signum()<0){return k.add(f)}else{return k}}var lowprimes=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997];var lplim=(1<<26)/lowprimes[lowprimes.length-1];function bnIsProbablePrime(e){var d,b=this.abs();if(b.t==1&&b[0]<=lowprimes[lowprimes.length-1]){for(d=0;d>1;if(f>lowprimes.length){f=lowprimes.length}var b=nbi();for(var e=0;e>8)&255;rng_pool[rng_pptr++]^=(a>>16)&255;rng_pool[rng_pptr++]^=(a>>24)&255;if(rng_pptr>=rng_psize){rng_pptr-=rng_psize}}function rng_seed_time(){rng_seed_int(new Date().getTime())}if(rng_pool==null){rng_pool=new Array();rng_pptr=0;var t;if(window!==undefined&&(window.crypto!==undefined||window.msCrypto!==undefined)){var crypto=window.crypto||window.msCrypto;if(crypto.getRandomValues){var ua=new Uint8Array(32);crypto.getRandomValues(ua);for(t=0;t<32;++t){rng_pool[rng_pptr++]=ua[t]}}else{if(navigator.appName=="Netscape"&&navigator.appVersion<"5"){var z=window.crypto.random(32);for(t=0;t>>8;rng_pool[rng_pptr++]=t&255}rng_pptr=0;rng_seed_time()}function rng_get_byte(){if(rng_state==null){rng_seed_time();rng_state=prng_newstate();rng_state.init(rng_pool);for(rng_pptr=0;rng_pptr=0&&h>0){var f=e.charCodeAt(d--);if(f<128){g[--h]=f}else{if((f>127)&&(f<2048)){g[--h]=(f&63)|128;g[--h]=(f>>6)|192}else{g[--h]=(f&63)|128;g[--h]=((f>>6)&63)|128;g[--h]=(f>>12)|224}}}g[--h]=0;var b=new SecureRandom();var a=new Array();while(h>2){a[0]=0;while(a[0]==0){b.nextBytes(a)}g[--h]=a[0]}g[--h]=2;g[--h]=0;return new BigInteger(g)}function oaep_mgf1_arr(c,a,e){var b="",d=0;while(b.length>24,(d&16711680)>>16,(d&65280)>>8,d&255])));d+=1}return b}function oaep_pad(q,a,f,l){var c=KJUR.crypto.MessageDigest;var o=KJUR.crypto.Util;var b=null;if(!f){f="sha1"}if(typeof f==="string"){b=c.getCanonicalAlgName(f);l=c.getHashLength(b);f=function(i){return hextorstr(o.hashHex(rstrtohex(i),b))}}if(q.length+2*l+2>a){throw"Message too long for RSA"}var k="",e;for(e=0;e0&&a.length>0){this.n=parseBigInt(b,16);this.e=parseInt(a,16)}else{throw"Invalid RSA public key"}}}function RSADoPublic(a){return a.modPowInt(this.e,this.n)}function RSAEncrypt(d){var a=pkcs1pad2(d,(this.n.bitLength()+7)>>3);if(a==null){return null}var e=this.doPublic(a);if(e==null){return null}var b=e.toString(16);if((b.length&1)==0){return b}else{return"0"+b}}function RSAEncryptOAEP(f,e,b){var i=(this.n.bitLength()+7)>>3;var a=oaep_pad(f,i,e,b);if(a==null){return null}var g=this.doPublic(a);if(g==null){return null}var d=g.toString(16);while(d.length=a.length){return null}}var e="";while(++f191)&&(h<224)){e+=String.fromCharCode(((h&31)<<6)|(a[f+1]&63));++f}else{e+=String.fromCharCode(((h&15)<<12)|((a[f+1]&63)<<6)|(a[f+2]&63));f+=2}}}return e}function oaep_mgf1_str(c,a,e){var b="",d=0;while(b.length>24,(d&16711680)>>16,(d&65280)>>8,d&255]));d+=1}return b}function oaep_unpad(o,b,g,p){var e=KJUR.crypto.MessageDigest;var r=KJUR.crypto.Util;var c=null;if(!g){g="sha1"}if(typeof g==="string"){c=e.getCanonicalAlgName(g);p=e.getHashLength(c);g=function(d){return hextorstr(r.hashHex(rstrtohex(d),c))}}o=o.toByteArray();var h;for(h=0;h0&&a.length>0){this.n=parseBigInt(c,16);this.e=parseInt(a,16);this.d=parseBigInt(b,16)}else{throw"Invalid RSA private key"}}}function RSASetPrivateEx(g,d,e,c,b,a,h,f){this.isPrivate=true;this.isPublic=false;if(g==null){throw"RSASetPrivateEx N == null"}if(d==null){throw"RSASetPrivateEx E == null"}if(g.length==0){throw"RSASetPrivateEx N.length == 0"}if(d.length==0){throw"RSASetPrivateEx E.length == 0"}if(g!=null&&d!=null&&g.length>0&&d.length>0){this.n=parseBigInt(g,16);this.e=parseInt(d,16);this.d=parseBigInt(e,16);this.p=parseBigInt(c,16);this.q=parseBigInt(b,16);this.dmp1=parseBigInt(a,16);this.dmq1=parseBigInt(h,16);this.coeff=parseBigInt(f,16)}else{throw"Invalid RSA private key in RSASetPrivateEx"}}function RSAGenerate(b,l){var a=new SecureRandom();var g=b>>1;this.e=parseInt(l,16);var c=new BigInteger(l,16);var d=(b/2)-100;var k=BigInteger.ONE.shiftLeft(d);for(;;){for(;;){this.p=new BigInteger(b-g,1,a);if(this.p.subtract(BigInteger.ONE).gcd(c).compareTo(BigInteger.ONE)==0&&this.p.isProbablePrime(10)){break}}for(;;){this.q=new BigInteger(g,1,a);if(this.q.subtract(BigInteger.ONE).gcd(c).compareTo(BigInteger.ONE)==0&&this.q.isProbablePrime(10)){break}}if(this.p.compareTo(this.q)<=0){var j=this.p;this.p=this.q;this.q=j}var h=this.q.subtract(this.p).abs();if(h.bitLength()>3)}function RSADecryptOAEP(e,d,b){if(e.length!=Math.ceil(this.n.bitLength()/4)){throw new Error("wrong ctext length")}var f=parseBigInt(e,16);var a=this.doPrivate(f);if(a==null){return null}return oaep_unpad(a,(this.n.bitLength()+7)>>3,d,b)}RSAKey.prototype.doPrivate=RSADoPrivate;RSAKey.prototype.setPrivate=RSASetPrivate;RSAKey.prototype.setPrivateEx=RSASetPrivateEx;RSAKey.prototype.generate=RSAGenerate;RSAKey.prototype.decrypt=RSADecrypt;RSAKey.prototype.decryptOAEP=RSADecryptOAEP; +/*! (c) Tom Wu | http://www-cs-students.stanford.edu/~tjw/jsbn/ + */ +function ECFieldElementFp(b,a){this.x=a;this.q=b}function feFpEquals(a){if(a==this){return true}return(this.q.equals(a.q)&&this.x.equals(a.x))}function feFpToBigInteger(){return this.x}function feFpNegate(){return new ECFieldElementFp(this.q,this.x.negate().mod(this.q))}function feFpAdd(a){return new ECFieldElementFp(this.q,this.x.add(a.toBigInteger()).mod(this.q))}function feFpSubtract(a){return new ECFieldElementFp(this.q,this.x.subtract(a.toBigInteger()).mod(this.q))}function feFpMultiply(a){return new ECFieldElementFp(this.q,this.x.multiply(a.toBigInteger()).mod(this.q))}function feFpSquare(){return new ECFieldElementFp(this.q,this.x.square().mod(this.q))}function feFpDivide(a){return new ECFieldElementFp(this.q,this.x.multiply(a.toBigInteger().modInverse(this.q)).mod(this.q))}ECFieldElementFp.prototype.equals=feFpEquals;ECFieldElementFp.prototype.toBigInteger=feFpToBigInteger;ECFieldElementFp.prototype.negate=feFpNegate;ECFieldElementFp.prototype.add=feFpAdd;ECFieldElementFp.prototype.subtract=feFpSubtract;ECFieldElementFp.prototype.multiply=feFpMultiply;ECFieldElementFp.prototype.square=feFpSquare;ECFieldElementFp.prototype.divide=feFpDivide;ECFieldElementFp.prototype.sqrt=function(){return new ECFieldElementFp(this.q,this.x.sqrt().mod(this.q))};function ECPointFp(c,a,d,b){this.curve=c;this.x=a;this.y=d;if(b==null){this.z=BigInteger.ONE}else{this.z=b}this.zinv=null}function pointFpGetX(){if(this.zinv==null){this.zinv=this.z.modInverse(this.curve.q)}return this.curve.fromBigInteger(this.x.toBigInteger().multiply(this.zinv).mod(this.curve.q))}function pointFpGetY(){if(this.zinv==null){this.zinv=this.z.modInverse(this.curve.q)}return this.curve.fromBigInteger(this.y.toBigInteger().multiply(this.zinv).mod(this.curve.q))}function pointFpEquals(a){if(a==this){return true}if(this.isInfinity()){return a.isInfinity()}if(a.isInfinity()){return this.isInfinity()}var c,b;c=a.y.toBigInteger().multiply(this.z).subtract(this.y.toBigInteger().multiply(a.z)).mod(this.curve.q);if(!c.equals(BigInteger.ZERO)){return false}b=a.x.toBigInteger().multiply(this.z).subtract(this.x.toBigInteger().multiply(a.z)).mod(this.curve.q);return b.equals(BigInteger.ZERO)}function pointFpIsInfinity(){if((this.x==null)&&(this.y==null)){return true}return this.z.equals(BigInteger.ZERO)&&!this.y.toBigInteger().equals(BigInteger.ZERO)}function pointFpNegate(){return new ECPointFp(this.curve,this.x,this.y.negate(),this.z)}function pointFpAdd(l){if(this.isInfinity()){return l}if(l.isInfinity()){return this}var p=l.y.toBigInteger().multiply(this.z).subtract(this.y.toBigInteger().multiply(l.z)).mod(this.curve.q);var o=l.x.toBigInteger().multiply(this.z).subtract(this.x.toBigInteger().multiply(l.z)).mod(this.curve.q);if(BigInteger.ZERO.equals(o)){if(BigInteger.ZERO.equals(p)){return this.twice()}return this.curve.getInfinity()}var j=new BigInteger("3");var e=this.x.toBigInteger();var n=this.y.toBigInteger();var c=l.x.toBigInteger();var k=l.y.toBigInteger();var m=o.square();var i=m.multiply(o);var d=e.multiply(m);var g=p.square().multiply(this.z);var a=g.subtract(d.shiftLeft(1)).multiply(l.z).subtract(i).multiply(o).mod(this.curve.q);var h=d.multiply(j).multiply(p).subtract(n.multiply(i)).subtract(g.multiply(p)).multiply(l.z).add(p.multiply(i)).mod(this.curve.q);var f=i.multiply(this.z).multiply(l.z).mod(this.curve.q);return new ECPointFp(this.curve,this.curve.fromBigInteger(a),this.curve.fromBigInteger(h),f)}function pointFpTwice(){if(this.isInfinity()){return this}if(this.y.toBigInteger().signum()==0){return this.curve.getInfinity()}var g=new BigInteger("3");var c=this.x.toBigInteger();var h=this.y.toBigInteger();var e=h.multiply(this.z);var j=e.multiply(h).mod(this.curve.q);var i=this.curve.a.toBigInteger();var k=c.square().multiply(g);if(!BigInteger.ZERO.equals(i)){k=k.add(this.z.square().multiply(i))}k=k.mod(this.curve.q);var b=k.square().subtract(c.shiftLeft(3).multiply(j)).shiftLeft(1).multiply(e).mod(this.curve.q);var f=k.multiply(g).multiply(c).subtract(j.shiftLeft(1)).shiftLeft(2).multiply(j).subtract(k.square().multiply(k)).mod(this.curve.q);var d=e.square().multiply(e).shiftLeft(3).mod(this.curve.q);return new ECPointFp(this.curve,this.curve.fromBigInteger(b),this.curve.fromBigInteger(f),d)}function pointFpMultiply(d){if(this.isInfinity()){return this}if(d.signum()==0){return this.curve.getInfinity()}var m=d;var l=m.multiply(new BigInteger("3"));var b=this.negate();var j=this;var q=this.curve.q.subtract(d);var o=q.multiply(new BigInteger("3"));var c=new ECPointFp(this.curve,this.x,this.y);var a=c.negate();var g;for(g=l.bitLength()-2;g>0;--g){j=j.twice();var n=l.testBit(g);var f=m.testBit(g);if(n!=f){j=j.add(n?this:b)}}for(g=o.bitLength()-2;g>0;--g){c=c.twice();var p=o.testBit(g);var r=q.testBit(g);if(p!=r){c=c.add(p?c:a)}}return j}function pointFpMultiplyTwo(c,a,b){var d;if(c.bitLength()>b.bitLength()){d=c.bitLength()-1}else{d=b.bitLength()-1}var f=this.curve.getInfinity();var e=this.add(a);while(d>=0){f=f.twice();if(c.testBit(d)){if(b.testBit(d)){f=f.add(e)}else{f=f.add(this)}}else{if(b.testBit(d)){f=f.add(a)}}--d}return f}ECPointFp.prototype.getX=pointFpGetX;ECPointFp.prototype.getY=pointFpGetY;ECPointFp.prototype.equals=pointFpEquals;ECPointFp.prototype.isInfinity=pointFpIsInfinity;ECPointFp.prototype.negate=pointFpNegate;ECPointFp.prototype.add=pointFpAdd;ECPointFp.prototype.twice=pointFpTwice;ECPointFp.prototype.multiply=pointFpMultiply;ECPointFp.prototype.multiplyTwo=pointFpMultiplyTwo;function ECCurveFp(e,d,c){this.q=e;this.a=this.fromBigInteger(d);this.b=this.fromBigInteger(c);this.infinity=new ECPointFp(this,null,null)}function curveFpGetQ(){return this.q}function curveFpGetA(){return this.a}function curveFpGetB(){return this.b}function curveFpEquals(a){if(a==this){return true}return(this.q.equals(a.q)&&this.a.equals(a.a)&&this.b.equals(a.b))}function curveFpGetInfinity(){return this.infinity}function curveFpFromBigInteger(a){return new ECFieldElementFp(this.q,a)}function curveFpDecodePointHex(m){switch(parseInt(m.substr(0,2),16)){case 0:return this.infinity;case 2:case 3:var c=m.substr(0,2);var l=m.substr(2);var j=this.fromBigInteger(new BigInteger(k,16));var i=this.getA();var h=this.getB();var e=j.square().add(i).multiply(j).add(h);var g=e.sqrt();if(c=="03"){g=g.negate()}return new ECPointFp(this,j,g);case 4:case 6:case 7:var d=(m.length-2)/2;var k=m.substr(2,d);var f=m.substr(d+2,d);return new ECPointFp(this,this.fromBigInteger(new BigInteger(k,16)),this.fromBigInteger(new BigInteger(f,16)));default:return null}}ECCurveFp.prototype.getQ=curveFpGetQ;ECCurveFp.prototype.getA=curveFpGetA;ECCurveFp.prototype.getB=curveFpGetB;ECCurveFp.prototype.equals=curveFpEquals;ECCurveFp.prototype.getInfinity=curveFpGetInfinity;ECCurveFp.prototype.fromBigInteger=curveFpFromBigInteger;ECCurveFp.prototype.decodePointHex=curveFpDecodePointHex; +/*! (c) Stefan Thomas | https://github.com/bitcoinjs/bitcoinjs-lib + */ +ECFieldElementFp.prototype.getByteLength=function(){return Math.floor((this.toBigInteger().bitLength()+7)/8)};ECPointFp.prototype.getEncoded=function(c){var d=function(h,f){var g=h.toByteArrayUnsigned();if(fg.length){g.unshift(0)}}return g};var a=this.getX().toBigInteger();var e=this.getY().toBigInteger();var b=d(a,32);if(c){if(e.isEven()){b.unshift(2)}else{b.unshift(3)}}else{b.unshift(4);b=b.concat(d(e,32))}return b};ECPointFp.decodeFrom=function(g,c){var f=c[0];var e=c.length-1;var d=c.slice(1,1+e/2);var b=c.slice(1+e/2,1+e);d.unshift(0);b.unshift(0);var a=new BigInteger(d);var h=new BigInteger(b);return new ECPointFp(g,g.fromBigInteger(a),g.fromBigInteger(h))};ECPointFp.decodeFromHex=function(g,c){var f=c.substr(0,2);var e=c.length-2;var d=c.substr(2,e/2);var b=c.substr(2+e/2,e/2);var a=new BigInteger(d,16);var h=new BigInteger(b,16);return new ECPointFp(g,g.fromBigInteger(a),g.fromBigInteger(h))};ECPointFp.prototype.add2D=function(c){if(this.isInfinity()){return c}if(c.isInfinity()){return this}if(this.x.equals(c.x)){if(this.y.equals(c.y)){return this.twice()}return this.curve.getInfinity()}var g=c.x.subtract(this.x);var e=c.y.subtract(this.y);var a=e.divide(g);var d=a.square().subtract(this.x).subtract(c.x);var f=a.multiply(this.x.subtract(d)).subtract(this.y);return new ECPointFp(this.curve,d,f)};ECPointFp.prototype.twice2D=function(){if(this.isInfinity()){return this}if(this.y.toBigInteger().signum()==0){return this.curve.getInfinity()}var b=this.curve.fromBigInteger(BigInteger.valueOf(2));var e=this.curve.fromBigInteger(BigInteger.valueOf(3));var a=this.x.square().multiply(e).add(this.curve.a).divide(this.y.multiply(b));var c=a.square().subtract(this.x.multiply(b));var d=a.multiply(this.x.subtract(c)).subtract(this.y);return new ECPointFp(this.curve,c,d)};ECPointFp.prototype.multiply2D=function(b){if(this.isInfinity()){return this}if(b.signum()==0){return this.curve.getInfinity()}var g=b;var f=g.multiply(new BigInteger("3"));var l=this.negate();var d=this;var c;for(c=f.bitLength()-2;c>0;--c){d=d.twice();var a=f.testBit(c);var j=g.testBit(c);if(a!=j){d=d.add2D(a?this:l)}}return d};ECPointFp.prototype.isOnCurve=function(){var d=this.getX().toBigInteger();var i=this.getY().toBigInteger();var f=this.curve.getA().toBigInteger();var c=this.curve.getB().toBigInteger();var h=this.curve.getQ();var e=i.multiply(i).mod(h);var g=d.multiply(d).multiply(d).add(f.multiply(d)).add(c).mod(h);return e.equals(g)};ECPointFp.prototype.toString=function(){return"("+this.getX().toBigInteger().toString()+","+this.getY().toBigInteger().toString()+")"};ECPointFp.prototype.validate=function(){var c=this.curve.getQ();if(this.isInfinity()){throw new Error("Point is at infinity.")}var a=this.getX().toBigInteger();var b=this.getY().toBigInteger();if(a.compareTo(BigInteger.ONE)<0||a.compareTo(c.subtract(BigInteger.ONE))>0){throw new Error("x coordinate out of bounds")}if(b.compareTo(BigInteger.ONE)<0||b.compareTo(c.subtract(BigInteger.ONE))>0){throw new Error("y coordinate out of bounds")}if(!this.isOnCurve()){throw new Error("Point is not on the curve.")}if(this.multiply(c).isInfinity()){throw new Error("Point is not a scalar multiple of G.")}return true}; +/*! Mike Samuel (c) 2009 | code.google.com/p/json-sans-eval + */ +var jsonParse=(function(){var e="(?:-?\\b(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?(?:[eE][+-]?[0-9]+)?\\b)";var j='(?:[^\\0-\\x08\\x0a-\\x1f"\\\\]|\\\\(?:["/\\\\bfnrt]|u[0-9A-Fa-f]{4}))';var i='(?:"'+j+'*")';var d=new RegExp("(?:false|true|null|[\\{\\}\\[\\]]|"+e+"|"+i+")","g");var k=new RegExp("\\\\(?:([^u])|u(.{4}))","g");var g={'"':'"',"/":"/","\\":"\\",b:"\b",f:"\f",n:"\n",r:"\r",t:"\t"};function h(l,m,n){return m?g[m]:String.fromCharCode(parseInt(n,16))}var c=new String("");var a="\\";var f={"{":Object,"[":Array};var b=Object.hasOwnProperty;return function(u,q){var p=u.match(d);var x;var v=p[0];var l=false;if("{"===v){x={}}else{if("["===v){x=[]}else{x=[];l=true}}var t;var r=[x];for(var o=1-l,m=p.length;o=0;){delete D[n[A]]}}}return q.call(C,B,D)};x=s({"":x},"")}return x}})(); +if(typeof KJUR=="undefined"||!KJUR){KJUR={}}if(typeof KJUR.asn1=="undefined"||!KJUR.asn1){KJUR.asn1={}}KJUR.asn1.ASN1Util=new function(){this.integerToByteHex=function(a){var b=a.toString(16);if((b.length%2)==1){b="0"+b}return b};this.bigIntToMinTwosComplementsHex=function(j){var f=j.toString(16);if(f.substr(0,1)!="-"){if(f.length%2==1){f="0"+f}else{if(!f.match(/^[0-7]/)){f="00"+f}}}else{var a=f.substr(1);var e=a.length;if(e%2==1){e+=1}else{if(!f.match(/^[0-7]/)){e+=2}}var g="";for(var d=0;d15){throw new Error("ASN.1 length too long to represent by 8x: n = "+j.toString(16))}var g=128+h;return g.toString(16)+i}};this.tohex=function(){if(this.hTLV==null||this.isModified){this.hV=this.getFreshValueHex();this.hL=this.getLengthHexFromValue();this.hTLV=this.hT+this.hL+this.hV;this.isModified=false}return this.hTLV};this.getEncodedHex=function(){return this.tohex()};this.getValueHex=function(){this.tohex();return this.hV};this.getFreshValueHex=function(){return""};this.setByParam=function(g){this.params=g};if(e!=undefined){if(e.tlv!=undefined){this.hTLV=e.tlv;this.isModified=false}}};KJUR.asn1.DERAbstractString=function(c){KJUR.asn1.DERAbstractString.superclass.constructor.call(this);var b=null;var a=null;this.getString=function(){return this.s};this.setString=function(d){this.hTLV=null;this.isModified=true;this.s=d;this.hV=utf8tohex(this.s).toLowerCase()};this.setStringHex=function(d){this.hTLV=null;this.isModified=true;this.s=null;this.hV=d};this.getFreshValueHex=function(){return this.hV};if(typeof c!="undefined"){if(typeof c=="string"){this.setString(c)}else{if(typeof c.str!="undefined"){this.setString(c.str)}else{if(typeof c.hex!="undefined"){this.setStringHex(c.hex)}}}}};extendClass(KJUR.asn1.DERAbstractString,KJUR.asn1.ASN1Object);KJUR.asn1.DERAbstractTime=function(c){KJUR.asn1.DERAbstractTime.superclass.constructor.call(this);var b=null;var a=null;this.localDateToUTC=function(g){var e=g.getTime()+(g.getTimezoneOffset()*60000);var f=new Date(e);return f};this.formatDate=function(m,o,e){var g=this.zeroPadding;var n=this.localDateToUTC(m);var p=String(n.getFullYear());if(o=="utc"){p=p.substr(2,2)}var l=g(String(n.getMonth()+1),2);var q=g(String(n.getDate()),2);var h=g(String(n.getHours()),2);var i=g(String(n.getMinutes()),2);var j=g(String(n.getSeconds()),2);var r=p+l+q+h+i+j;if(e===true){var f=n.getMilliseconds();if(f!=0){var k=g(String(f),3);k=k.replace(/[0]+$/,"");r=r+"."+k}}return r+"Z"};this.zeroPadding=function(e,d){if(e.length>=d){return e}return new Array(d-e.length+1).join("0")+e};this.setByParam=function(d){this.hV=null;this.hTLV=null;this.params=d};this.getString=function(){return undefined};this.setString=function(d){this.hTLV=null;this.isModified=true;if(this.params==undefined){this.params={}}this.params.str=d};this.setByDate=function(d){this.hTLV=null;this.isModified=true;if(this.params==undefined){this.params={}}this.params.date=d};this.setByDateValue=function(h,j,e,d,f,g){var i=new Date(Date.UTC(h,j-1,e,d,f,g,0));this.setByDate(i)};this.getFreshValueHex=function(){return this.hV}};extendClass(KJUR.asn1.DERAbstractTime,KJUR.asn1.ASN1Object);KJUR.asn1.DERAbstractStructured=function(b){KJUR.asn1.DERAbstractString.superclass.constructor.call(this);var a=null;this.setByASN1ObjectArray=function(c){this.hTLV=null;this.isModified=true;this.asn1Array=c};this.appendASN1Object=function(c){this.hTLV=null;this.isModified=true;this.asn1Array.push(c)};this.asn1Array=new Array();if(typeof b!="undefined"){if(typeof b.array!="undefined"){this.asn1Array=b.array}}};extendClass(KJUR.asn1.DERAbstractStructured,KJUR.asn1.ASN1Object);KJUR.asn1.DERBoolean=function(a){KJUR.asn1.DERBoolean.superclass.constructor.call(this);this.hT="01";if(a==false){this.hTLV="010100"}else{this.hTLV="0101ff"}};extendClass(KJUR.asn1.DERBoolean,KJUR.asn1.ASN1Object);KJUR.asn1.DERInteger=function(b){KJUR.asn1.DERInteger.superclass.constructor.call(this);this.hT="02";this.params=null;var a=KJUR.asn1.ASN1Util.bigIntToMinTwosComplementsHex;this.setByBigInteger=function(c){this.isModified=true;this.params={bigint:c}};this.setByInteger=function(c){this.isModified=true;this.params=c};this.setValueHex=function(c){this.isModified=true;this.params={hex:c}};this.getFreshValueHex=function(){var d=this.params;var c=null;if(d==null){throw new Error("value not set")}if(typeof d=="object"&&d.hex!=undefined){this.hV=d.hex;return this.hV}if(typeof d=="number"){c=new BigInteger(String(d),10)}else{if(d["int"]!=undefined){c=new BigInteger(String(d["int"]),10)}else{if(d.bigint!=undefined){c=d.bigint}else{throw new Error("wrong parameter")}}}this.hV=a(c);return this.hV};if(b!=undefined){this.params=b}};extendClass(KJUR.asn1.DERInteger,KJUR.asn1.ASN1Object);KJUR.asn1.DERBitString=function(b){if(b!==undefined&&typeof b.obj!=="undefined"){var a=KJUR.asn1.ASN1Util.newObject(b.obj);b.hex="00"+a.tohex()}KJUR.asn1.DERBitString.superclass.constructor.call(this);this.hT="03";this.setHexValueIncludingUnusedBits=function(c){this.hTLV=null;this.isModified=true;this.hV=c};this.setUnusedBitsAndHexValue=function(c,e){if(c<0||7=f){break}}return j};ASN1HEX.getNthChildIdx=function(d,b,e){var c=ASN1HEX.getChildIdx(d,b);return c[e]};ASN1HEX.getIdxbyList=function(e,d,c,i){var g=ASN1HEX;var f,b;if(c.length==0){if(i!==undefined){if(e.substr(d,2)!==i){return -1}}return d}f=c.shift();b=g.getChildIdx(e,d);if(f>=b.length){return -1}return g.getIdxbyList(e,b[f],c,i)};ASN1HEX.getIdxbyListEx=function(f,k,b,g){var m=ASN1HEX;var d,l;if(b.length==0){if(g!==undefined){if(f.substr(k,2)!==g){return -1}}return k}d=b.shift();l=m.getChildIdx(f,k);var j=0;for(var e=0;e=d.length){return null}return e.getTLV(d,a)};ASN1HEX.getTLVbyListEx=function(d,c,b,f){var e=ASN1HEX;var a=e.getIdxbyListEx(d,c,b,f);if(a==-1){return null}return e.getTLV(d,a)};ASN1HEX.getVbyList=function(e,c,b,g,i){var f=ASN1HEX;var a,d;a=f.getIdxbyList(e,c,b,g);if(a==-1){return null}if(a>=e.length){return null}d=f.getV(e,a);if(i===true){d=d.substr(2)}return d};ASN1HEX.getVbyListEx=function(b,e,a,d,f){var j=ASN1HEX;var g,c,i;g=j.getIdxbyListEx(b,e,a,d);if(g==-1){return null}i=j.getV(b,g);if(b.substr(g,2)=="03"&&f!==false){i=i.substr(2)}return i};ASN1HEX.getInt=function(e,b,f){if(f==undefined){f=-1}try{var c=e.substr(b,2);if(c!="02"&&c!="03"){return f}var a=ASN1HEX.getV(e,b);if(c=="02"){return parseInt(a,16)}else{return bitstrtoint(a)}}catch(d){return f}};ASN1HEX.getOID=function(c,a,d){if(d==undefined){d=null}try{if(c.substr(a,2)!="06"){return d}var e=ASN1HEX.getV(c,a);return hextooid(e)}catch(b){return d}};ASN1HEX.getOIDName=function(d,a,f){if(f==undefined){f=null}try{var e=ASN1HEX.getOID(d,a,f);if(e==f){return f}var b=KJUR.asn1.x509.OID.oid2name(e);if(b==""){return e}return b}catch(c){return f}};ASN1HEX.getString=function(d,b,e){if(e==undefined){e=null}try{var a=ASN1HEX.getV(d,b);return hextorstr(a)}catch(c){return e}};ASN1HEX.hextooidstr=function(e){var h=function(b,a){if(b.length>=a){return b}return new Array(a-b.length+1).join("0")+b};var l=[];var o=e.substr(0,2);var f=parseInt(o,16);l[0]=new String(Math.floor(f/40));l[1]=new String(f%40);var m=e.substr(2);var k=[];for(var g=0;g0){n=n+"."+j.join(".")}return n};ASN1HEX.dump=function(t,c,l,g){var p=ASN1HEX;var j=p.getV;var y=p.dump;var w=p.getChildIdx;var e=t;if(t instanceof KJUR.asn1.ASN1Object){e=t.tohex()}var q=function(A,i){if(A.length<=i*2){return A}else{var v=A.substr(0,i)+"..(total "+A.length/2+"bytes).."+A.substr(A.length-i,i);return v}};if(c===undefined){c={ommit_long_octet:32}}if(l===undefined){l=0}if(g===undefined){g=""}var x=c.ommit_long_octet;var z=e.substr(l,2);if(z=="01"){var h=j(e,l);if(h=="00"){return g+"BOOLEAN FALSE\n"}else{return g+"BOOLEAN TRUE\n"}}if(z=="02"){var h=j(e,l);return g+"INTEGER "+q(h,x)+"\n"}if(z=="03"){var h=j(e,l);if(p.isASN1HEX(h.substr(2))){var k=g+"BITSTRING, encapsulates\n";k=k+y(h.substr(2),c,0,g+" ");return k}else{return g+"BITSTRING "+q(h,x)+"\n"}}if(z=="04"){var h=j(e,l);if(p.isASN1HEX(h)){var k=g+"OCTETSTRING, encapsulates\n";k=k+y(h,c,0,g+" ");return k}else{return g+"OCTETSTRING "+q(h,x)+"\n"}}if(z=="05"){return g+"NULL\n"}if(z=="06"){var m=j(e,l);var b=KJUR.asn1.ASN1Util.oidHexToInt(m);var o=KJUR.asn1.x509.OID.oid2name(b);var a=b.replace(/\./g," ");if(o!=""){return g+"ObjectIdentifier "+o+" ("+a+")\n"}else{return g+"ObjectIdentifier ("+a+")\n"}}if(z=="0a"){return g+"ENUMERATED "+parseInt(j(e,l))+"\n"}if(z=="0c"){return g+"UTF8String '"+hextoutf8(j(e,l))+"'\n"}if(z=="13"){return g+"PrintableString '"+hextoutf8(j(e,l))+"'\n"}if(z=="14"){return g+"TeletexString '"+hextoutf8(j(e,l))+"'\n"}if(z=="16"){return g+"IA5String '"+hextoutf8(j(e,l))+"'\n"}if(z=="17"){return g+"UTCTime "+hextoutf8(j(e,l))+"\n"}if(z=="18"){return g+"GeneralizedTime "+hextoutf8(j(e,l))+"\n"}if(z=="1a"){return g+"VisualString '"+hextoutf8(j(e,l))+"'\n"}if(z=="1e"){return g+"BMPString '"+ucs2hextoutf8(j(e,l))+"'\n"}if(z=="30"){if(e.substr(l,4)=="3000"){return g+"SEQUENCE {}\n"}var k=g+"SEQUENCE\n";var d=w(e,l);var f=c;if((d.length==2||d.length==3)&&e.substr(d[0],2)=="06"&&e.substr(d[d.length-1],2)=="04"){var o=p.oidname(j(e,d[0]));var r=JSON.parse(JSON.stringify(c));r.x509ExtName=o;f=r}for(var u=0;u4){return{"enum":{hex:p}}}else{return{"enum":parseInt(p,16)}}}else{if(C=="30"||C=="31"){j[c[C]]=u(x);return j}else{if(C=="14"){var o=q(p);j[c[C]]={str:o};return j}else{if(C=="1e"){var o=n(p);j[c[C]]={str:o};return j}else{if(":0c:12:13:16:17:18:1a:".indexOf(C)!=-1){var o=k(p);j[c[C]]={str:o};return j}else{if(C.match(/^8[0-9]$/)){var o=k(p);if(o==null|o==""){return{tag:{tag:C,explicit:false,hex:p}}}else{if(o.match(/[\x00-\x1F\x7F-\x9F]/)!=null||o.match(/[\u0000-\u001F\u0080–\u009F]/)!=null){return{tag:{tag:C,explicit:false,hex:p}}}else{return{tag:{tag:C,explicit:false,str:o}}}}}else{if(C.match(/^a[0-9]$/)){try{if(!a(p)){throw new Error("not encap")}return{tag:{tag:C,explicit:true,obj:f(p)}}}catch(z){return{tag:{tag:C,explicit:true,hex:p}}}}else{var A=new KJUR.asn1.ASN1Object();A.hV=p;var w=A.getLengthHexFromValue();return{asn1:{tlv:C+w+p}}}}}}}}}}}}}}}};ASN1HEX.isContextTag=function(c,b){c=c.toLowerCase();var f,e;try{f=parseInt(c,16)}catch(d){return -1}if(b===undefined){if((f&192)==128){return true}else{return false}}try{var a=b.match(/^\[[0-9]+\]$/);if(a==null){return false}e=parseInt(b.substr(1,b.length-1),10);if(e>31){return false}if(((f&192)==128)&&((f&31)==e)){return true}return false}catch(d){return false}};ASN1HEX.isASN1HEX=function(e){var d=ASN1HEX;if(e.length%2==1){return false}var c=d.getVblen(e,0);var b=e.substr(0,2);var f=d.getL(e,0);var a=e.length-b.length-f.length;if(a==c*2){return true}return false};ASN1HEX.checkStrictDER=function(g,o,d,c,r){var s=ASN1HEX;if(d===undefined){if(typeof g!="string"){throw new Error("not hex string")}g=g.toLowerCase();if(!KJUR.lang.String.isHex(g)){throw new Error("not hex string")}d=g.length;c=g.length/2;if(c<128){r=1}else{r=Math.ceil(c.toString(16))+1}}var k=s.getL(g,o);if(k.length>r*2){throw new Error("L of TLV too long: idx="+o)}var n=s.getVblen(g,o);if(n>c){throw new Error("value of L too long than hex: idx="+o)}var q=s.getTLV(g,o);var f=q.length-2-s.getL(g,o).length;if(f!==(n*2)){throw new Error("V string length and L's value not the same:"+f+"/"+(n*2))}if(o===0){if(g.length!=q.length){throw new Error("total length and TLV length unmatch:"+g.length+"!="+q.length)}}var b=g.substr(o,2);if(b==="02"){var a=s.getVidx(g,o);if(g.substr(a,2)=="00"&&g.charCodeAt(a+2)<56){throw new Error("not least zeros for DER INTEGER")}}if(parseInt(b,16)&32){var p=s.getVblen(g,o);var m=0;var l=s.getChildIdx(g,o);for(var e=0;e0){n.push(new c({tag:"a3",obj:new j(q.ext)}))}var o=new KJUR.asn1.DERSequence({array:n});return o.tohex()};this.getEncodedHex=function(){return this.tohex()};if(f!==undefined){this.setByParam(f)}};extendClass(KJUR.asn1.x509.TBSCertificate,KJUR.asn1.ASN1Object);KJUR.asn1.x509.Extensions=function(d){KJUR.asn1.x509.Extensions.superclass.constructor.call(this);var c=KJUR,b=c.asn1,a=b.DERSequence,e=b.x509;this.aParam=[];this.setByParam=function(f){this.aParam=f};this.tohex=function(){var f=[];for(var h=0;h-1){i.push(new f({"int":this.pathLen}))}var h=new b({array:i});this.asn1ExtnValue=h;return this.asn1ExtnValue.tohex()};this.oid="2.5.29.19";this.cA=false;this.pathLen=-1;if(g!==undefined){if(g.cA!==undefined){this.cA=g.cA}if(g.pathLen!==undefined){this.pathLen=g.pathLen}}};extendClass(KJUR.asn1.x509.BasicConstraints,KJUR.asn1.x509.Extension);KJUR.asn1.x509.CRLDistributionPoints=function(d){KJUR.asn1.x509.CRLDistributionPoints.superclass.constructor.call(this,d);var b=KJUR,a=b.asn1,c=a.x509;this.getExtnValueHex=function(){return this.asn1ExtnValue.tohex()};this.setByDPArray=function(e){var f=[];for(var g=0;g0){f.push(new b({array:j}))}}var g=new b({array:f});return g.tohex()};this.getEncodedHex=function(){return this.tohex()};if(d!==undefined){this.params=d}};extendClass(KJUR.asn1.x509.PolicyInformation,KJUR.asn1.ASN1Object);KJUR.asn1.x509.PolicyQualifierInfo=function(e){KJUR.asn1.x509.PolicyQualifierInfo.superclass.constructor.call(this,e);var c=KJUR.asn1,b=c.DERSequence,d=c.DERIA5String,f=c.DERObjectIdentifier,a=c.x509.UserNotice;this.params=null;this.tohex=function(){if(this.params.cps!==undefined){var g=new b({array:[new f({oid:"1.3.6.1.5.5.7.2.1"}),new d({str:this.params.cps})]});return g.tohex()}if(this.params.unotice!=undefined){var g=new b({array:[new f({oid:"1.3.6.1.5.5.7.2.2"}),new a(this.params.unotice)]});return g.tohex()}};this.getEncodedHex=function(){return this.tohex()};if(e!==undefined){this.params=e}};extendClass(KJUR.asn1.x509.PolicyQualifierInfo,KJUR.asn1.ASN1Object);KJUR.asn1.x509.UserNotice=function(e){KJUR.asn1.x509.UserNotice.superclass.constructor.call(this,e);var a=KJUR.asn1.DERSequence,d=KJUR.asn1.DERInteger,c=KJUR.asn1.x509.DisplayText,b=KJUR.asn1.x509.NoticeReference;this.params=null;this.tohex=function(){var f=[];if(this.params.noticeref!==undefined){f.push(new b(this.params.noticeref))}if(this.params.exptext!==undefined){f.push(new c(this.params.exptext))}var g=new a({array:f});return g.tohex()};this.getEncodedHex=function(){return this.tohex()};if(e!==undefined){this.params=e}};extendClass(KJUR.asn1.x509.UserNotice,KJUR.asn1.ASN1Object);KJUR.asn1.x509.NoticeReference=function(d){KJUR.asn1.x509.NoticeReference.superclass.constructor.call(this,d);var a=KJUR.asn1.DERSequence,c=KJUR.asn1.DERInteger,b=KJUR.asn1.x509.DisplayText;this.params=null;this.tohex=function(){var f=[];if(this.params.org!==undefined){f.push(new b(this.params.org))}if(this.params.noticenum!==undefined){var h=[];var e=this.params.noticenum;for(var j=0;j0){for(var g=0;g0;f++){var h=c.shift();if(e===true){var d=b.pop();var j=(d+","+h).replace(/\\,/g,",");b.push(j);e=false}else{b.push(h)}if(h.substr(-1,1)==="\\"){e=true}}b=b.map(function(a){return a.replace("/","\\/")});b.reverse();return"/"+b.join("/")};KJUR.asn1.x509.X500Name.ldapToOneline=function(a){return KJUR.asn1.x509.X500Name.ldapToCompat(a)};KJUR.asn1.x509.RDN=function(b){KJUR.asn1.x509.RDN.superclass.constructor.call(this);this.asn1Array=[];this.paramArray=[];this.sRule="utf8";var a=KJUR.asn1.x509.AttributeTypeAndValue;this.setByParam=function(c){if(c.rule!==undefined){this.sRule=c.rule}if(c.str!==undefined){this.addByMultiValuedString(c.str)}if(c.array!==undefined){this.paramArray=c.array}};this.addByString=function(c){this.asn1Array.push(new KJUR.asn1.x509.AttributeTypeAndValue({str:c,rule:this.sRule}))};this.addByMultiValuedString=function(e){var c=KJUR.asn1.x509.RDN.parseString(e);for(var d=0;d0){for(var d=0;d0;g++){var k=j.shift();if(h===true){var f=c.pop();var d=(f+"+"+k).replace(/\\\+/g,"+");c.push(d);h=false}else{c.push(k)}if(k.substr(-1,1)==="\\"){h=true}}var l=false;var b=[];for(var g=0;c.length>0;g++){var k=c.shift();if(l===true){var e=b.pop();if(k.match(/"$/)){var d=(e+"+"+k).replace(/^([^=]+)="(.*)"$/,"$1=$2");b.push(d);l=false}else{b.push(e+"+"+k)}}else{b.push(k)}if(k.match(/^[^=]+="/)){l=true}}return b};KJUR.asn1.x509.AttributeTypeAndValue=function(c){KJUR.asn1.x509.AttributeTypeAndValue.superclass.constructor.call(this);this.sRule="utf8";this.sType=null;this.sValue=null;this.dsType=null;var a=KJUR,g=a.asn1,d=g.DERSequence,l=g.DERUTF8String,i=g.DERPrintableString,h=g.DERTeletexString,b=g.DERIA5String,e=g.DERVisibleString,k=g.DERBMPString,f=a.lang.String.isMail,j=a.lang.String.isPrintable;this.setByParam=function(o){if(o.rule!==undefined){this.sRule=o.rule}if(o.ds!==undefined){this.dsType=o.ds}if(o.value===undefined&&o.str!==undefined){var n=o.str;var m=n.match(/^([^=]+)=(.+)$/);if(m){this.sType=m[1];this.sValue=m[2]}else{throw new Error("malformed attrTypeAndValueStr: "+attrTypeAndValueStr)}}else{this.sType=o.type;this.sValue=o.value}};this.setByString=function(n,o){if(o!==undefined){this.sRule=o}var m=n.match(/^([^=]+)=(.+)$/);if(m){this.setByAttrTypeAndValueStr(m[1],m[2])}else{throw new Error("malformed attrTypeAndValueStr: "+attrTypeAndValueStr)}};this._getDsType=function(){var o=this.sType;var n=this.sValue;var m=this.sRule;if(m==="prn"){if(o=="CN"&&f(n)){return"ia5"}if(j(n)){return"prn"}return"utf8"}else{if(m==="utf8"){if(o=="CN"&&f(n)){return"ia5"}if(o=="C"){return"prn"}return"utf8"}}return"utf8"};this.setByAttrTypeAndValueStr=function(o,n,m){if(m!==undefined){this.sRule=m}this.sType=o;this.sValue=n};this.getValueObj=function(n,m){if(n=="utf8"){return new l({str:m})}if(n=="prn"){return new i({str:m})}if(n=="tel"){return new h({str:m})}if(n=="ia5"){return new b({str:m})}if(n=="vis"){return new e({str:m})}if(n=="bmp"){return new k({str:m})}throw new Error("unsupported directory string type: type="+n+" value="+m)};this.tohex=function(){if(this.dsType==null){this.dsType=this._getDsType()}var n=KJUR.asn1.x509.OID.atype2obj(this.sType);var m=this.getValueObj(this.dsType,this.sValue);var p=new d({array:[n,m]});this.TLV=p.tohex();return this.TLV};this.getEncodedHex=function(){return this.tohex()};if(c!==undefined){this.setByParam(c)}};extendClass(KJUR.asn1.x509.AttributeTypeAndValue,KJUR.asn1.ASN1Object);KJUR.asn1.x509.SubjectPublicKeyInfo=function(f){KJUR.asn1.x509.SubjectPublicKeyInfo.superclass.constructor.call(this);var l=null,k=null,a=KJUR,j=a.asn1,i=j.DERInteger,b=j.DERBitString,m=j.DERObjectIdentifier,e=j.DERSequence,h=j.ASN1Util.newObject,d=j.x509,o=d.AlgorithmIdentifier,g=a.crypto,n=g.ECDSA,c=g.DSA;this.getASN1Object=function(){if(this.asn1AlgId==null||this.asn1SubjPKey==null){throw"algId and/or subjPubKey not set"}var p=new e({array:[this.asn1AlgId,this.asn1SubjPKey]});return p};this.tohex=function(){var p=this.getASN1Object();this.hTLV=p.tohex();return this.hTLV};this.getEncodedHex=function(){return this.tohex()};this.setPubKey=function(q){try{if(q instanceof RSAKey){var u=h({seq:[{"int":{bigint:q.n}},{"int":{"int":q.e}}]});var s=u.tohex();this.asn1AlgId=new o({name:"rsaEncryption"});this.asn1SubjPKey=new b({hex:"00"+s})}}catch(p){}try{if(q instanceof KJUR.crypto.ECDSA){var r=new m({name:q.curveName});this.asn1AlgId=new o({name:"ecPublicKey",asn1params:r});this.asn1SubjPKey=new b({hex:"00"+q.pubKeyHex})}}catch(p){}try{if(q instanceof KJUR.crypto.DSA){var r=new h({seq:[{"int":{bigint:q.p}},{"int":{bigint:q.q}},{"int":{bigint:q.g}}]});this.asn1AlgId=new o({name:"dsa",asn1params:r});var t=new i({bigint:q.y});this.asn1SubjPKey=new b({hex:"00"+t.tohex()})}}catch(p){}};if(f!==undefined){this.setPubKey(f)}};extendClass(KJUR.asn1.x509.SubjectPublicKeyInfo,KJUR.asn1.ASN1Object);KJUR.asn1.x509.Time=function(f){KJUR.asn1.x509.Time.superclass.constructor.call(this);var e=null,a=null,d=KJUR,c=d.asn1,b=c.DERUTCTime,g=c.DERGeneralizedTime;this.params=null;this.type=null;this.setTimeParams=function(h){this.timeParams=h};this.setByParam=function(h){this.params=h};this.getType=function(h){if(h.match(/^[0-9]{12}Z$/)){return"utc"}if(h.match(/^[0-9]{14}Z$/)){return"gen"}if(h.match(/^[0-9]{12}\.[0-9]+Z$/)){return"utc"}if(h.match(/^[0-9]{14}\.[0-9]+Z$/)){return"gen"}return null};this.tohex=function(){var i=this.params;var h=null;if(typeof i=="string"){i={str:i}}if(i!=null&&i.str&&(i.type==null||i.type==undefined)){i.type=this.getType(i.str)}if(i!=null&&i.str){if(i.type=="utc"){h=new b(i.str)}if(i.type=="gen"){h=new g(i.str)}}else{if(this.type=="gen"){h=new g()}else{h=new b()}}if(h==null){throw new Error("wrong setting for Time")}this.TLV=h.tohex();return this.TLV};this.getEncodedHex=function(){return this.tohex()};if(f!=undefined){this.setByParam(f)}};KJUR.asn1.x509.Time_bak=function(f){KJUR.asn1.x509.Time_bak.superclass.constructor.call(this);var e=null,a=null,d=KJUR,c=d.asn1,b=c.DERUTCTime,g=c.DERGeneralizedTime;this.setTimeParams=function(h){this.timeParams=h};this.tohex=function(){var h=null;if(this.timeParams!=null){if(this.type=="utc"){h=new b(this.timeParams)}else{h=new g(this.timeParams)}}else{if(this.type=="utc"){h=new b()}else{h=new g()}}this.TLV=h.tohex();return this.TLV};this.getEncodedHex=function(){return this.tohex()};this.type="utc";if(f!==undefined){if(f.type!==undefined){this.type=f.type}else{if(f.str!==undefined){if(f.str.match(/^[0-9]{12}Z$/)){this.type="utc"}if(f.str.match(/^[0-9]{14}Z$/)){this.type="gen"}}}this.timeParams=f}};extendClass(KJUR.asn1.x509.Time,KJUR.asn1.ASN1Object);KJUR.asn1.x509.AlgorithmIdentifier=function(e){KJUR.asn1.x509.AlgorithmIdentifier.superclass.constructor.call(this);this.nameAlg=null;this.asn1Alg=null;this.asn1Params=null;this.paramEmpty=false;var b=KJUR,a=b.asn1,c=a.x509.AlgorithmIdentifier.PSSNAME2ASN1TLV;this.tohex=function(){if(this.nameAlg===null&&this.asn1Alg===null){throw new Error("algorithm not specified")}if(this.nameAlg!==null){var f=null;for(var h in c){if(h===this.nameAlg){f=c[h]}}if(f!==null){this.hTLV=f;return this.hTLV}}if(this.nameAlg!==null&&this.asn1Alg===null){this.asn1Alg=a.x509.OID.name2obj(this.nameAlg)}var g=[this.asn1Alg];if(this.asn1Params!==null){g.push(this.asn1Params)}var i=new a.DERSequence({array:g});this.hTLV=i.tohex();return this.hTLV};this.getEncodedHex=function(){return this.tohex()};if(e!==undefined){if(e.name!==undefined){this.nameAlg=e.name}if(e.asn1params!==undefined){this.asn1Params=e.asn1params}if(e.paramempty!==undefined){this.paramEmpty=e.paramempty}}if(this.asn1Params===null&&this.paramEmpty===false&&this.nameAlg!==null){if(this.nameAlg.name!==undefined){this.nameAlg=this.nameAlg.name}var d=this.nameAlg.toLowerCase();if(d.substr(-7,7)!=="withdsa"&&d.substr(-9,9)!=="withecdsa"){this.asn1Params=new a.DERNull()}}};extendClass(KJUR.asn1.x509.AlgorithmIdentifier,KJUR.asn1.ASN1Object);KJUR.asn1.x509.AlgorithmIdentifier.PSSNAME2ASN1TLV={SHAwithRSAandMGF1:"300d06092a864886f70d01010a3000",SHA256withRSAandMGF1:"303d06092a864886f70d01010a3030a00d300b0609608648016503040201a11a301806092a864886f70d010108300b0609608648016503040201a203020120",SHA384withRSAandMGF1:"303d06092a864886f70d01010a3030a00d300b0609608648016503040202a11a301806092a864886f70d010108300b0609608648016503040202a203020130",SHA512withRSAandMGF1:"303d06092a864886f70d01010a3030a00d300b0609608648016503040203a11a301806092a864886f70d010108300b0609608648016503040203a203020140"};KJUR.asn1.x509.GeneralName=function(f){KJUR.asn1.x509.GeneralName.superclass.constructor.call(this);var l={rfc822:"81",dns:"82",dn:"a4",uri:"86",ip:"87",otherName:"a0"},b=KJUR,h=b.asn1,d=h.x509,a=d.X500Name,g=d.OtherName,e=h.DERIA5String,i=h.DERPrintableString,k=h.DEROctetString,c=h.DERTaggedObject,m=h.ASN1Object,j=Error;this.params=null;this.setByParam=function(n){this.params=n};this.tohex=function(){var p=this.params;var A,y,q;var y=false;if(p.other!==undefined){A="a0",q=new g(p.other)}else{if(p.rfc822!==undefined){A="81";q=new e({str:p.rfc822})}else{if(p.dns!==undefined){A="82";q=new e({str:p.dns})}else{if(p.dn!==undefined){A="a4";y=true;if(typeof p.dn==="string"){q=new a({str:p.dn})}else{if(p.dn instanceof KJUR.asn1.x509.X500Name){q=p.dn}else{q=new a(p.dn)}}}else{if(p.ldapdn!==undefined){A="a4";y=true;q=new a({ldapstr:p.ldapdn})}else{if(p.certissuer!==undefined||p.certsubj!==undefined){A="a4";y=true;var n,o;var z=null;if(p.certsubj!==undefined){n=false;o=p.certsubj}else{n=true;o=p.certissuer}if(o.match(/^[0-9A-Fa-f]+$/)){z==o}if(o.indexOf("-----BEGIN ")!=-1){z=pemtohex(o)}if(z==null){throw new Error("certsubj/certissuer not cert")}var w=new X509();w.hex=z;var s;if(n){s=w.getIssuerHex()}else{s=w.getSubjectHex()}q=new m();q.hTLV=s}else{if(p.uri!==undefined){A="86";q=new e({str:p.uri})}else{if(p.ip!==undefined){A="87";var v;var t=p.ip;try{if(t.match(/^[0-9a-f]+$/)){var r=t.length;if(r==8||r==16||r==32||r==64){v=t}else{throw"err"}}else{v=iptohex(t)}}catch(u){throw new j("malformed IP address: "+p.ip+":"+u.message)}q=new k({hex:v})}else{throw new j("improper params")}}}}}}}}var B=new c({tag:A,explicit:y,obj:q});return B.tohex()};this.getEncodedHex=function(){return this.tohex()};if(f!==undefined){this.setByParam(f)}};extendClass(KJUR.asn1.x509.GeneralName,KJUR.asn1.ASN1Object);KJUR.asn1.x509.GeneralNames=function(d){KJUR.asn1.x509.GeneralNames.superclass.constructor.call(this);var a=null,c=KJUR,b=c.asn1;this.setByParamArray=function(g){for(var e=0;e0){var m=b(n.valhex,q[0]);var p=j(m,0);var t=[];for(var o=0;o1){var r=b(n.valhex,q[1]);n.polhex=r}delete n.valhex};this.setSignaturePolicyIdentifier=function(s){var q=j(s.valhex,0);if(q.length>0){var r=l.getOID(s.valhex,q[0]);s.oid=r}if(q.length>1){var m=new a();var t=j(s.valhex,q[1]);var p=b(s.valhex,t[0]);var o=m.getAlgorithmIdentifierName(p);s.alg=o;var n=i(s.valhex,t[1]);s.hash=n}delete s.valhex};this.setSigningCertificateV2=function(o){var s=j(o.valhex,0);if(s.length>0){var n=b(o.valhex,s[0]);var r=j(n,0);var u=[];for(var q=0;q1){var t=b(o.valhex,s[1]);o.polhex=t}delete o.valhex};this.getESSCertID=function(o){var p={};var n=j(o,0);if(n.length>0){var q=i(o,n[0]);p.hash=q}if(n.length>1){var m=b(o,n[1]);var r=this.getIssuerSerial(m);if(r.serial!=undefined){p.serial=r.serial}if(r.issuer!=undefined){p.issuer=r.issuer}}return p};this.getESSCertIDv2=function(q){var s={};var p=j(q,0);if(p.length<1||3r+1){var m=b(q,p[r+1]);var t=this.getIssuerSerial(m);s.issuer=t.issuer;s.serial=t.serial}return s};this.getIssuerSerial=function(q){var r={};var n=j(q,0);var m=b(q,n[0]);var p=h.getGeneralNames(m);var o=p[0].dn;r.issuer=o;var s=i(q,n[1]);r.serial={hex:s};return r};this.getCertificateSet=function(p){var n=j(p,0);var m=[];for(var o=0;o=0;j--){l+=k[j]}return l}else{if(typeof n=="string"&&a[n]!=undefined){return namearraytobinstr([n],a)}else{if(typeof n=="object"&&n.length!=undefined){return namearraytobinstr(n,a)}else{throw new f("wrong params")}}}return};this.tohex=function(){var j=this.params;var i=this.getBinValue();return(new g({bin:i})).tohex()};this.getEncodedHex=function(){return this.tohex()};if(h!=undefined){this.setByParam(h)}};extendClass(KJUR.asn1.tsp.PKIFailureInfo,KJUR.asn1.ASN1Object);KJUR.asn1.tsp.AbstractTSAAdapter=function(a){this.getTSTHex=function(c,b){throw"not implemented yet"}};KJUR.asn1.tsp.SimpleTSAAdapter=function(e){var d=KJUR,c=d.asn1,a=c.tsp,b=d.crypto.Util.hashHex;a.SimpleTSAAdapter.superclass.constructor.call(this);this.params=null;this.serial=0;this.getTSTHex=function(g,f){var i=b(g,f);this.params.econtent.content.messageImprint={alg:f,hash:i};this.params.econtent.content.serial={"int":this.serial++};var h=Math.floor(Math.random()*1000000000);this.params.econtent.content.nonce={"int":h};var j=new a.TimeStampToken(this.params);return j.getContentInfoEncodedHex()};if(e!==undefined){this.params=e}};extendClass(KJUR.asn1.tsp.SimpleTSAAdapter,KJUR.asn1.tsp.AbstractTSAAdapter);KJUR.asn1.tsp.FixedTSAAdapter=function(e){var d=KJUR,c=d.asn1,a=c.tsp,b=d.crypto.Util.hashHex;a.FixedTSAAdapter.superclass.constructor.call(this);this.params=null;this.getTSTHex=function(g,f){var h=b(g,f);this.params.econtent.content.messageImprint={alg:f,hash:h};var i=new a.TimeStampToken(this.params);return i.getContentInfoEncodedHex()};if(e!==undefined){this.params=e}};extendClass(KJUR.asn1.tsp.FixedTSAAdapter,KJUR.asn1.tsp.AbstractTSAAdapter);KJUR.asn1.tsp.TSPUtil=new function(){};KJUR.asn1.tsp.TSPUtil.newTimeStampToken=function(a){return new KJUR.asn1.tsp.TimeStampToken(a)};KJUR.asn1.tsp.TSPUtil.parseTimeStampReq=function(a){var b=new KJUR.asn1.tsp.TSPParser();return b.getTimeStampReq(a)};KJUR.asn1.tsp.TSPUtil.parseMessageImprint=function(a){var b=new KJUR.asn1.tsp.TSPParser();return b.getMessageImprint(a)};KJUR.asn1.tsp.TSPParser=function(){var e=Error,a=X509,f=new a(),k=ASN1HEX,g=k.getV,b=k.getTLV,d=k.getIdxbyList,c=k.getTLVbyListEx,i=k.getChildIdx;var j=["granted","grantedWithMods","rejection","waiting","revocationWarning","revocationNotification"];var h={0:"badAlg",2:"badRequest",5:"badDataFormat",14:"timeNotAvailable",15:"unacceptedPolicy",16:"unacceptedExtension",17:"addInfoNotAvailable",25:"systemFailure"};this.getResponse=function(n){var l=i(n,0);if(l.length==1){return this.getPKIStatusInfo(b(n,l[0]))}else{if(l.length>1){var o=this.getPKIStatusInfo(b(n,l[0]));var m=b(n,l[1]);var p=this.getToken(m);p.statusinfo=o;return p}}};this.getToken=function(m){var l=new KJUR.asn1.cms.CMSParser;var n=l.getCMSSignedData(m);this.setTSTInfo(n);return n};this.setTSTInfo=function(l){var o=l.econtent;if(o.type=="tstinfo"){var n=o.content.hex;var m=this.getTSTInfo(n);o.content=m}};this.getTSTInfo=function(r){var x={};var s=i(r,0);var p=g(r,s[1]);x.policy=hextooid(p);var o=b(r,s[2]);x.messageImprint=this.getMessageImprint(o);var u=g(r,s[3]);x.serial={hex:u};var y=g(r,s[4]);x.genTime={str:hextoutf8(y)};var q=0;if(s.length>5&&r.substr(s[5],2)=="30"){var v=b(r,s[5]);x.accuracy=this.getAccuracy(v);q++}if(s.length>5+q&&r.substr(s[5+q],2)=="01"){var z=g(r,s[5+q]);if(z=="ff"){x.ordering=true}q++}if(s.length>5+q&&r.substr(s[5+q],2)=="02"){var n=g(r,s[5+q]);x.nonce={hex:n};q++}if(s.length>5+q&&r.substr(s[5+q],2)=="a0"){var m=b(r,s[5+q]);m="30"+m.substr(2);pGeneralNames=f.getGeneralNames(m);var t=pGeneralNames[0].dn;x.tsa=t;q++}if(s.length>5+q&&r.substr(s[5+q],2)=="a1"){var l=b(r,s[5+q]);l="30"+l.substr(2);var w=f.getExtParamArray(l);x.ext=w;q++}return x};this.getAccuracy=function(q){var r={};var o=i(q,0);for(var p=0;p1&&o.substr(r[1],2)=="30"){var m=b(o,r[1]);t.statusstr=this.getPKIFreeText(m);n++}if(r.length>n&&o.substr(r[1+n],2)=="03"){var q=b(o,r[1+n]);t.failinfo=this.getPKIFailureInfo(q)}return t};this.getPKIFreeText=function(n){var o=[];var l=i(n,0);for(var m=0;m>6);var i=128|(a&63);return hextoutf8(j.toString(16)+i.toString(16))}var j=224|((h&240)>>4);var i=128|((h&15)<<2)|((a&192)>>6);var g=128|(a&63);return hextoutf8(j.toString(16)+i.toString(16)+g.toString(16))}var c=d.match(/.{4}/g);var b=c.map(e);return b.join("")}function encodeURIComponentAll(a){var d=encodeURIComponent(a);var b="";for(var c=0;c"7"){return"00"+a}return a}function intarystrtohex(b){b=b.replace(/^\s*\[\s*/,"");b=b.replace(/\s*\]\s*$/,"");b=b.replace(/\s*/g,"");try{var c=b.split(/,/).map(function(g,e,h){var f=parseInt(g);if(f<0||255a.length){d=a.length}for(var b=0;b0){o=o+"."+k.join(".")}return o}catch(j){return null}}var strpad=function(c,b,a){if(a==undefined){a="0"}if(c.length>=b){return c}return new Array(b-c.length+1).join(a)+c};function bitstrtoint(e){if(e.length%2!=0){return -1}e=e.toLowerCase();if(e.match(/^[0-9a-f]+$/)==null){return -1}try{var a=e.substr(0,2);if(a=="00"){return parseInt(e.substr(2),16)}var b=parseInt(a,16);if(b>7){return -1}var g=e.substr(2);var d=parseInt(g,16).toString(2);if(d=="0"){d="00000000"}d=d.slice(0,0-b);var f=parseInt(d,2);if(f==NaN){return -1}return f}catch(c){return -1}}function inttobitstr(e){if(typeof e!="number"){return null}if(e<0){return null}var c=Number(e).toString(2);var b=8-c.length%8;if(b==8){b=0}c=c+strpad("",b,"0");var d=parseInt(c,2).toString(16);if(d.length%2==1){d="0"+d}var a="0"+b;return a+d}function bitstrtobinstr(g){if(typeof g!="string"){return null}if(g.length%2!=0){return null}if(!g.match(/^[0-9a-f]+$/)){return null}try{var c=parseInt(g.substr(0,2),16);if(c<0||7=0;a--){c+=b[a]}return c}function aryval(e,c,d){if(typeof e!="object"){return undefined}var c=String(c).split(".");for(var b=0;bd){throw"key is too short for SigAlg: keylen="+j+","+a}var b="0001";var k="00"+c;var g="";var l=d-b.length-k.length;for(var f=0;f=0;--u){v=v.twice2D();v.z=f.ONE;if(t.testBit(u)){if(s.testBit(u)){v=v.add2D(y)}else{v=v.add2D(x)}}else{if(s.testBit(u)){v=v.add2D(w)}}}return v}this.getBigRandom=function(r){return new f(r.bitLength(),a).mod(r.subtract(f.ONE)).add(f.ONE)};this.setNamedCurve=function(r){this.ecparams=c.getByName(r);this.prvKeyHex=null;this.pubKeyHex=null;this.curveName=r};this.setPrivateKeyHex=function(r){this.isPrivate=true;this.prvKeyHex=r};this.setPublicKeyHex=function(r){this.isPublic=true;this.pubKeyHex=r};this.getPublicKeyXYHex=function(){var t=this.pubKeyHex;if(t.substr(0,2)!=="04"){throw"this method supports uncompressed format(04) only"}var s=this.ecparams.keycharlen;if(t.length!==2+s*2){throw"malformed public key hex length"}var r={};r.x=t.substr(2,s);r.y=t.substr(2+s);return r};this.getShortNISTPCurveName=function(){var r=this.curveName;if(r==="secp256r1"||r==="NIST P-256"||r==="P-256"||r==="prime256v1"){return"P-256"}if(r==="secp384r1"||r==="NIST P-384"||r==="P-384"){return"P-384"}if(r==="secp521r1"||r==="NIST P-521"||r==="P-521"){return"P-521"}return null};this.generateKeyPairHex=function(){var s=this.ecparams.n;var u=this.getBigRandom(s);var r=this.ecparams.keycharlen;var t=("0000000000"+u.toString(16)).slice(-r);this.setPrivateKeyHex(t);var v=this.generatePublicKeyHex();return{ecprvhex:t,ecpubhex:v}};this.generatePublicKeyHex=function(){var u=new f(this.prvKeyHex,16);var w=this.ecparams.G.multiply(u);var t=w.getX().toBigInteger();var s=w.getY().toBigInteger();var r=this.ecparams.keycharlen;var y=("0000000000"+t.toString(16)).slice(-r);var v=("0000000000"+s.toString(16)).slice(-r);var x="04"+y+v;this.setPublicKeyHex(x);return x};this.signWithMessageHash=function(r){return this.signHex(r,this.prvKeyHex)};this.signHex=function(x,u){var A=new f(u,16);var v=this.ecparams.n;var z=new f(x.substring(0,this.ecparams.keycharlen),16);do{var w=this.getBigRandom(v);var B=this.ecparams.G;var y=B.multiply(w);var t=y.getX().toBigInteger().mod(v)}while(t.compareTo(f.ZERO)<=0);var C=w.modInverse(v).multiply(z.add(A.multiply(t))).mod(v);return m.biRSSigToASN1Sig(t,C)};this.sign=function(w,B){var z=B;var u=this.ecparams.n;var y=f.fromByteArrayUnsigned(w);do{var v=this.getBigRandom(u);var A=this.ecparams.G;var x=A.multiply(v);var t=x.getX().toBigInteger().mod(u)}while(t.compareTo(BigInteger.ZERO)<=0);var C=v.modInverse(u).multiply(y.add(z.multiply(t))).mod(u);return this.serializeSig(t,C)};this.verifyWithMessageHash=function(s,r){return this.verifyHex(s,r,this.pubKeyHex)};this.verifyHex=function(v,y,u){try{var t,B;var w=m.parseSigHex(y);t=w.r;B=w.s;var x=h.decodeFromHex(this.ecparams.curve,u);var z=new f(v.substring(0,this.ecparams.keycharlen),16);return this.verifyRaw(z,t,B,x)}catch(A){return false}};this.verify=function(z,A,u){var w,t;if(Bitcoin.Util.isArray(A)){var y=this.parseSig(A);w=y.r;t=y.s}else{if("object"===typeof A&&A.r&&A.s){w=A.r;t=A.s}else{throw"Invalid value for signature"}}var v;if(u instanceof ECPointFp){v=u}else{if(Bitcoin.Util.isArray(u)){v=h.decodeFrom(this.ecparams.curve,u)}else{throw"Invalid format for pubkey value, must be byte array or ECPointFp"}}var x=f.fromByteArrayUnsigned(z);return this.verifyRaw(x,w,t,v)};this.verifyRaw=function(z,t,E,y){var x=this.ecparams.n;var D=this.ecparams.G;if(t.compareTo(f.ONE)<0||t.compareTo(x)>=0){return false}if(E.compareTo(f.ONE)<0||E.compareTo(x)>=0){return false}var A=E.modInverse(x);var w=z.multiply(A).mod(x);var u=t.multiply(A).mod(x);var B=D.multiply(w).add(y.multiply(u));var C=B.getX().toBigInteger().mod(x);return C.equals(t)};this.serializeSig=function(v,u){var w=v.toByteArraySigned();var t=u.toByteArraySigned();var x=[];x.push(2);x.push(w.length);x=x.concat(w);x.push(2);x.push(t.length);x=x.concat(t);x.unshift(x.length);x.unshift(48);return x};this.parseSig=function(y){var x;if(y[0]!=48){throw new Error("Signature not a valid DERSequence")}x=2;if(y[x]!=2){throw new Error("First element in signature must be a DERInteger")}var w=y.slice(x+2,x+2+y[x+1]);x+=2+y[x+1];if(y[x]!=2){throw new Error("Second element in signature must be a DERInteger")}var t=y.slice(x+2,x+2+y[x+1]);x+=2+y[x+1];var v=f.fromByteArrayUnsigned(w);var u=f.fromByteArrayUnsigned(t);return{r:v,s:u}};this.parseSigCompact=function(w){if(w.length!==65){throw"Signature has the wrong length"}var t=w[0]-27;if(t<0||t>7){throw"Invalid signature type"}var x=this.ecparams.n;var v=f.fromByteArrayUnsigned(w.slice(1,33)).mod(x);var u=f.fromByteArrayUnsigned(w.slice(33,65)).mod(x);return{r:v,s:u,i:t}};this.readPKCS5PrvKeyHex=function(u){if(k(u)===false){throw new Error("not ASN.1 hex string")}var r,t,v;try{r=n(u,0,["[0]",0],"06");t=n(u,0,[1],"04");try{v=n(u,0,["[1]",0],"03")}catch(s){}}catch(s){throw new Error("malformed PKCS#1/5 plain ECC private key")}this.curveName=d(r);if(this.curveName===undefined){throw"unsupported curve name"}this.setNamedCurve(this.curveName);this.setPublicKeyHex(v);this.setPrivateKeyHex(t);this.isPublic=false};this.readPKCS8PrvKeyHex=function(v){if(k(v)===false){throw new j("not ASN.1 hex string")}var t,r,u,w;try{t=n(v,0,[1,0],"06");r=n(v,0,[1,1],"06");u=n(v,0,[2,0,1],"04");try{w=n(v,0,[2,0,"[1]",0],"03")}catch(s){}}catch(s){throw new j("malformed PKCS#8 plain ECC private key")}this.curveName=d(r);if(this.curveName===undefined){throw new j("unsupported curve name")}this.setNamedCurve(this.curveName);this.setPublicKeyHex(w);this.setPrivateKeyHex(u);this.isPublic=false};this.readPKCS8PubKeyHex=function(u){if(k(u)===false){throw new j("not ASN.1 hex string")}var t,r,v;try{t=n(u,0,[0,0],"06");r=n(u,0,[0,1],"06");v=n(u,0,[1],"03")}catch(s){throw new j("malformed PKCS#8 ECC public key")}this.curveName=d(r);if(this.curveName===null){throw new j("unsupported curve name")}this.setNamedCurve(this.curveName);this.setPublicKeyHex(v)};this.readCertPubKeyHex=function(t,v){if(k(t)===false){throw new j("not ASN.1 hex string")}var r,u;try{r=n(t,0,[0,5,0,1],"06");u=n(t,0,[0,5,1],"03")}catch(s){throw new j("malformed X.509 certificate ECC public key")}this.curveName=d(r);if(this.curveName===null){throw new j("unsupported curve name")}this.setNamedCurve(this.curveName);this.setPublicKeyHex(u)};if(e!==undefined){if(e.curve!==undefined){this.curveName=e.curve}}if(this.curveName===undefined){this.curveName=g}this.setNamedCurve(this.curveName);if(e!==undefined){if(e.prv!==undefined){this.setPrivateKeyHex(e.prv)}if(e.pub!==undefined){this.setPublicKeyHex(e.pub)}}};KJUR.crypto.ECDSA.parseSigHex=function(a){var b=KJUR.crypto.ECDSA.parseSigHexInHexRS(a);var d=new BigInteger(b.r,16);var c=new BigInteger(b.s,16);return{r:d,s:c}};KJUR.crypto.ECDSA.parseSigHexInHexRS=function(f){var j=ASN1HEX,i=j.getChildIdx,g=j.getV;j.checkStrictDER(f,0);if(f.substr(0,2)!="30"){throw new Error("signature is not a ASN.1 sequence")}var h=i(f,0);if(h.length!=2){throw new Error("signature shall have two elements")}var e=h[0];var d=h[1];if(f.substr(e,2)!="02"){throw new Error("1st item not ASN.1 integer")}if(f.substr(d,2)!="02"){throw new Error("2nd item not ASN.1 integer")}var c=g(f,e);var b=g(f,d);return{r:c,s:b}};KJUR.crypto.ECDSA.asn1SigToConcatSig=function(d){var e=KJUR.crypto.ECDSA.parseSigHexInHexRS(d);var b=e.r;var a=e.s;if(b.length>=130&&b.length<=134){if(b.length%2!=0){throw Error("unknown ECDSA sig r length error")}if(a.length%2!=0){throw Error("unknown ECDSA sig s length error")}if(b.substr(0,2)=="00"){b=b.substr(2)}if(a.substr(0,2)=="00"){a=a.substr(2)}var c=Math.max(b.length,a.length);b=("000000"+b).slice(-c);a=("000000"+a).slice(-c);return b+a}if(b.substr(0,2)=="00"&&(b.length%32)==2){b=b.substr(2)}if(a.substr(0,2)=="00"&&(a.length%32)==2){a=a.substr(2)}if((b.length%32)==30){b="00"+b}if((a.length%32)==30){a="00"+a}if(b.length%32!=0){throw Error("unknown ECDSA sig r length error")}if(a.length%32!=0){throw Error("unknown ECDSA sig s length error")}return b+a};KJUR.crypto.ECDSA.concatSigToASN1Sig=function(a){if(a.length%4!=0){throw Error("unknown ECDSA concatinated r-s sig length error")}var c=a.substr(0,a.length/2);var b=a.substr(a.length/2);return KJUR.crypto.ECDSA.hexRSSigToASN1Sig(c,b)};KJUR.crypto.ECDSA.hexRSSigToASN1Sig=function(b,a){var d=new BigInteger(b,16);var c=new BigInteger(a,16);return KJUR.crypto.ECDSA.biRSSigToASN1Sig(d,c)};KJUR.crypto.ECDSA.biRSSigToASN1Sig=function(f,d){var c=KJUR.asn1;var b=new c.DERInteger({bigint:f});var a=new c.DERInteger({bigint:d});var e=new c.DERSequence({array:[b,a]});return e.tohex()};KJUR.crypto.ECDSA.getName=function(a){if(a==="2b8104001f"){return"secp192k1"}if(a==="2a8648ce3d030107"){return"secp256r1"}if(a==="2b8104000a"){return"secp256k1"}if(a==="2b81040021"){return"secp224r1"}if(a==="2b81040022"){return"secp384r1"}if(a==="2b81040023"){return"secp521r1"}if("|secp256r1|NIST P-256|P-256|prime256v1|".indexOf(a)!==-1){return"secp256r1"}if("|secp256k1|".indexOf(a)!==-1){return"secp256k1"}if("|secp224r1|NIST P-224|P-224|".indexOf(a)!==-1){return"secp224r1"}if("|secp384r1|NIST P-384|P-384|".indexOf(a)!==-1){return"secp384r1"}if("|secp521r1|NIST P-521|P-521|".indexOf(a)!==-1){return"secp521r1"}return null}; +if(typeof KJUR=="undefined"||!KJUR){KJUR={}}if(typeof KJUR.crypto=="undefined"||!KJUR.crypto){KJUR.crypto={}}KJUR.crypto.ECParameterDB=new function(){var b={};var c={};function a(d){return new BigInteger(d,16)}this.getByName=function(e){var d=e;if(typeof c[d]!="undefined"){d=c[e]}if(typeof b[d]!="undefined"){return b[d]}throw"unregistered EC curve name: "+d};this.regist=function(A,l,o,g,m,e,j,f,k,u,d,x){b[A]={};var s=a(o);var z=a(g);var y=a(m);var t=a(e);var w=a(j);var r=new ECCurveFp(s,z,y);var q=r.decodePointHex("04"+f+k);b[A]["name"]=A;b[A]["keylen"]=l;b[A]["keycharlen"]=Math.ceil(l/8)*2;b[A]["curve"]=r;b[A]["G"]=q;b[A]["n"]=t;b[A]["h"]=w;b[A]["oid"]=d;b[A]["info"]=x;for(var v=0;v1){l=new BigInteger(n,16)}else{l=null}m=new BigInteger(o,16);this.setPrivate(h,f,j,l,m)};this.setPublic=function(i,h,f,j){this.isPublic=true;this.p=i;this.q=h;this.g=f;this.y=j;this.x=null};this.setPublicHex=function(k,j,i,l){var g,f,m,h;g=new BigInteger(k,16);f=new BigInteger(j,16);m=new BigInteger(i,16);h=new BigInteger(l,16);this.setPublic(g,f,m,h)};this.signWithMessageHash=function(j){var i=this.p;var h=this.q;var m=this.g;var o=this.y;var t=this.x;var l=KJUR.crypto.Util.getRandomBigIntegerMinToMax(BigInteger.ONE.add(BigInteger.ONE),h.subtract(BigInteger.ONE));var u=j.substr(0,h.bitLength()/4);var n=new BigInteger(u,16);var f=(m.modPow(l,i)).mod(h);var w=(l.modInverse(h).multiply(n.add(t.multiply(f)))).mod(h);var v=KJUR.asn1.ASN1Util.jsonToASN1HEX({seq:[{"int":{bigint:f}},{"int":{bigint:w}}]});return v};this.verifyWithMessageHash=function(m,l){var j=this.p;var h=this.q;var o=this.g;var u=this.y;var n=this.parseASN1Signature(l);var f=n[0];var C=n[1];var B=m.substr(0,h.bitLength()/4);var t=new BigInteger(B,16);if(BigInteger.ZERO.compareTo(f)>0||f.compareTo(h)>0){throw"invalid DSA signature"}if(BigInteger.ZERO.compareTo(C)>=0||C.compareTo(h)>0){throw"invalid DSA signature"}var x=C.modInverse(h);var k=t.multiply(x).mod(h);var i=f.multiply(x).mod(h);var A=o.modPow(k,j).multiply(u.modPow(i,j)).mod(j).mod(h);return A.compareTo(f)==0};this.parseASN1Signature=function(f){try{var i=new c(d(f,0,[0],"02"),16);var h=new c(d(f,0,[1],"02"),16);return[i,h]}catch(g){throw new Error("malformed ASN.1 DSA signature")}};this.readPKCS5PrvKeyHex=function(j){var k,i,g,l,m;if(a(j)===false){throw new Error("not ASN.1 hex string")}try{k=d(j,0,[1],"02");i=d(j,0,[2],"02");g=d(j,0,[3],"02");l=d(j,0,[4],"02");m=d(j,0,[5],"02")}catch(f){throw new Error("malformed PKCS#1/5 plain DSA private key")}this.setPrivateHex(k,i,g,l,m)};this.readPKCS8PrvKeyHex=function(j){var k,i,g,l;if(a(j)===false){throw new Error("not ASN.1 hex string")}try{k=d(j,0,[1,1,0],"02");i=d(j,0,[1,1,1],"02");g=d(j,0,[1,1,2],"02");l=d(j,0,[2,0],"02")}catch(f){throw new Error("malformed PKCS#8 plain DSA private key")}this.setPrivateHex(k,i,g,null,l)};this.readPKCS8PubKeyHex=function(j){var k,i,g,l;if(a(j)===false){throw new Error("not ASN.1 hex string")}try{k=d(j,0,[0,1,0],"02");i=d(j,0,[0,1,1],"02");g=d(j,0,[0,1,2],"02");l=d(j,0,[1,0],"02")}catch(f){throw new Error("malformed PKCS#8 DSA public key")}this.setPublicHex(k,i,g,l)};this.readCertPubKeyHex=function(j,m){var k,i,g,l;if(a(j)===false){throw new Error("not ASN.1 hex string")}try{k=d(j,0,[0,5,0,1,0],"02");i=d(j,0,[0,5,0,1,1],"02");g=d(j,0,[0,5,0,1,2],"02");l=d(j,0,[0,5,1,0],"02")}catch(f){throw new Error("malformed X.509 certificate DSA public key")}this.setPublicHex(k,i,g,l)}}; +var KEYUTIL=function(){var d=function(p,r,q){return k(CryptoJS.AES,p,r,q)};var e=function(p,r,q){return k(CryptoJS.TripleDES,p,r,q)};var a=function(p,r,q){return k(CryptoJS.DES,p,r,q)};var k=function(s,x,u,q){var r=CryptoJS.enc.Hex.parse(x);var w=CryptoJS.enc.Hex.parse(u);var p=CryptoJS.enc.Hex.parse(q);var t={};t.key=w;t.iv=p;t.ciphertext=r;var v=s.decrypt(t,w,{iv:p});return CryptoJS.enc.Hex.stringify(v)};var l=function(p,r,q){return g(CryptoJS.AES,p,r,q)};var o=function(p,r,q){return g(CryptoJS.TripleDES,p,r,q)};var f=function(p,r,q){return g(CryptoJS.DES,p,r,q)};var g=function(t,y,v,q){var s=CryptoJS.enc.Hex.parse(y);var x=CryptoJS.enc.Hex.parse(v);var p=CryptoJS.enc.Hex.parse(q);var w=t.encrypt(s,x,{iv:p});var r=CryptoJS.enc.Hex.parse(w.toString());var u=CryptoJS.enc.Base64.stringify(r);return u};var i={"AES-256-CBC":{proc:d,eproc:l,keylen:32,ivlen:16},"AES-192-CBC":{proc:d,eproc:l,keylen:24,ivlen:16},"AES-128-CBC":{proc:d,eproc:l,keylen:16,ivlen:16},"DES-EDE3-CBC":{proc:e,eproc:o,keylen:24,ivlen:8},"DES-CBC":{proc:a,eproc:f,keylen:8,ivlen:8}};var c=function(p){return i[p]["proc"]};var m=function(p){var r=CryptoJS.lib.WordArray.random(p);var q=CryptoJS.enc.Hex.stringify(r);return q};var n=function(v){var w={};var q=v.match(new RegExp("DEK-Info: ([^,]+),([0-9A-Fa-f]+)","m"));if(q){w.cipher=q[1];w.ivsalt=q[2]}var p=v.match(new RegExp("-----BEGIN ([A-Z]+) PRIVATE KEY-----"));if(p){w.type=p[1]}var u=-1;var x=0;if(v.indexOf("\r\n\r\n")!=-1){u=v.indexOf("\r\n\r\n");x=2}if(v.indexOf("\n\n")!=-1){u=v.indexOf("\n\n");x=1}var t=v.indexOf("-----END");if(u!=-1&&t!=-1){var r=v.substring(u+x*2,t-x);r=r.replace(/\s+/g,"");w.data=r}return w};var j=function(q,y,p){var v=p.substring(0,16);var t=CryptoJS.enc.Hex.parse(v);var r=CryptoJS.enc.Utf8.parse(y);var u=i[q]["keylen"]+i[q]["ivlen"];var x="";var w=null;for(;;){var s=CryptoJS.algo.MD5.create();if(w!=null){s.update(w)}s.update(r);s.update(t);w=s.finalize();x=x+CryptoJS.enc.Hex.stringify(w);if(x.length>=u*2){break}}var z={};z.keyhex=x.substr(0,i[q]["keylen"]*2);z.ivhex=x.substr(i[q]["keylen"]*2,i[q]["ivlen"]*2);return z};var b=function(p,v,r,w){var s=CryptoJS.enc.Base64.parse(p);var q=CryptoJS.enc.Hex.stringify(s);var u=i[v]["proc"];var t=u(q,r,w);return t};var h=function(p,s,q,u){var r=i[s]["eproc"];var t=r(p,q,u);return t};return{version:"1.0.0",parsePKCS5PEM:function(p){return n(p)},getKeyAndUnusedIvByPasscodeAndIvsalt:function(q,p,r){return j(q,p,r)},decryptKeyB64:function(p,r,q,s){return b(p,r,q,s)},getDecryptedKeyHex:function(y,x){var q=n(y);var t=q.type;var r=q.cipher;var p=q.ivsalt;var s=q.data;var w=j(r,x,p);var v=w.keyhex;var u=b(s,r,v,p);return u},getEncryptedPKCS5PEMFromPrvKeyHex:function(x,s,A,t,r){var p="";if(typeof t=="undefined"||t==null){t="AES-256-CBC"}if(typeof i[t]=="undefined"){throw new Error("KEYUTIL unsupported algorithm: "+t)}if(typeof r=="undefined"||r==null){var v=i[t]["ivlen"];var u=m(v);r=u.toUpperCase()}var z=j(t,A,r);var y=z.keyhex;var w=h(s,t,y,r);var q=w.replace(/(.{64})/g,"$1\r\n");var p="-----BEGIN "+x+" PRIVATE KEY-----\r\n";p+="Proc-Type: 4,ENCRYPTED\r\n";p+="DEK-Info: "+t+","+r+"\r\n";p+="\r\n";p+=q;p+="\r\n-----END "+x+" PRIVATE KEY-----\r\n";return p},parseHexOfEncryptedPKCS8:function(y){var B=ASN1HEX;var z=B.getChildIdx;var w=B.getV;var t={};var r=z(y,0);if(r.length!=2){throw new Error("malformed format: SEQUENCE(0).items != 2: "+r.length)}t.ciphertext=w(y,r[1]);var A=z(y,r[0]);if(A.length!=2){throw new Error("malformed format: SEQUENCE(0.0).items != 2: "+A.length)}if(w(y,A[0])!="2a864886f70d01050d"){throw new Error("this only supports pkcs5PBES2")}var p=z(y,A[1]);if(A.length!=2){throw new Error("malformed format: SEQUENCE(0.0.1).items != 2: "+p.length)}var q=z(y,p[1]);if(q.length!=2){throw new Error("malformed format: SEQUENCE(0.0.1.1).items != 2: "+q.length)}if(w(y,q[0])!="2a864886f70d0307"){throw"this only supports TripleDES"}t.encryptionSchemeAlg="TripleDES";t.encryptionSchemeIV=w(y,q[1]);var s=z(y,p[0]);if(s.length!=2){throw new Error("malformed format: SEQUENCE(0.0.1.0).items != 2: "+s.length)}if(w(y,s[0])!="2a864886f70d01050c"){throw new Error("this only supports pkcs5PBKDF2")}var x=z(y,s[1]);if(x.length<2){throw new Error("malformed format: SEQUENCE(0.0.1.0.1).items < 2: "+x.length)}t.pbkdf2Salt=w(y,x[0]);var u=w(y,x[1]);try{t.pbkdf2Iter=parseInt(u,16)}catch(v){throw new Error("malformed format pbkdf2Iter: "+u)}return t},getPBKDF2KeyHexFromParam:function(u,p){var t=CryptoJS.enc.Hex.parse(u.pbkdf2Salt);var q=u.pbkdf2Iter;var s=CryptoJS.PBKDF2(p,t,{keySize:192/32,iterations:q});var r=CryptoJS.enc.Hex.stringify(s);return r},_getPlainPKCS8HexFromEncryptedPKCS8PEM:function(x,y){var r=pemtohex(x,"ENCRYPTED PRIVATE KEY");var p=this.parseHexOfEncryptedPKCS8(r);var u=KEYUTIL.getPBKDF2KeyHexFromParam(p,y);var v={};v.ciphertext=CryptoJS.enc.Hex.parse(p.ciphertext);var t=CryptoJS.enc.Hex.parse(u);var s=CryptoJS.enc.Hex.parse(p.encryptionSchemeIV);var w=CryptoJS.TripleDES.decrypt(v,t,{iv:s});var q=CryptoJS.enc.Hex.stringify(w);return q},getKeyFromEncryptedPKCS8PEM:function(s,q){var p=this._getPlainPKCS8HexFromEncryptedPKCS8PEM(s,q);var r=this.getKeyFromPlainPrivatePKCS8Hex(p);return r},parsePlainPrivatePKCS8Hex:function(s){var v=ASN1HEX;var u=v.getChildIdx;var t=v.getV;var q={};q.algparam=null;if(s.substr(0,2)!="30"){throw new Error("malformed plain PKCS8 private key(code:001)")}var r=u(s,0);if(r.length<3){throw new Error("malformed plain PKCS8 private key(code:002)")}if(s.substr(r[1],2)!="30"){throw new Error("malformed PKCS8 private key(code:003)")}var p=u(s,r[1]);if(p.length!=2){throw new Error("malformed PKCS8 private key(code:004)")}if(s.substr(p[0],2)!="06"){throw new Error("malformed PKCS8 private key(code:005)")}q.algoid=t(s,p[0]);if(s.substr(p[1],2)=="06"){q.algparam=t(s,p[1])}if(s.substr(r[2],2)!="04"){throw new Error("malformed PKCS8 private key(code:006)")}q.keyidx=v.getVidx(s,r[2]);return q},getKeyFromPlainPrivatePKCS8PEM:function(q){var p=pemtohex(q,"PRIVATE KEY");var r=this.getKeyFromPlainPrivatePKCS8Hex(p);return r},getKeyFromPlainPrivatePKCS8Hex:function(p){var q=this.parsePlainPrivatePKCS8Hex(p);var r;if(q.algoid=="2a864886f70d010101"){r=new RSAKey()}else{if(q.algoid=="2a8648ce380401"){r=new KJUR.crypto.DSA()}else{if(q.algoid=="2a8648ce3d0201"){r=new KJUR.crypto.ECDSA()}else{throw new Error("unsupported private key algorithm")}}}r.readPKCS8PrvKeyHex(p);return r},_getKeyFromPublicPKCS8Hex:function(q){var p;var r=ASN1HEX.getVbyList(q,0,[0,0],"06");if(r==="2a864886f70d010101"){p=new RSAKey()}else{if(r==="2a8648ce380401"){p=new KJUR.crypto.DSA()}else{if(r==="2a8648ce3d0201"){p=new KJUR.crypto.ECDSA()}else{throw new Error("unsupported PKCS#8 public key hex")}}}p.readPKCS8PubKeyHex(q);return p},parsePublicRawRSAKeyHex:function(r){var u=ASN1HEX;var t=u.getChildIdx;var s=u.getV;var p={};if(r.substr(0,2)!="30"){throw new Error("malformed RSA key(code:001)")}var q=t(r,0);if(q.length!=2){throw new Error("malformed RSA key(code:002)")}if(r.substr(q[0],2)!="02"){throw new Error("malformed RSA key(code:003)")}p.n=s(r,q[0]);if(r.substr(q[1],2)!="02"){throw new Error("malformed RSA key(code:004)")}p.e=s(r,q[1]);return p},parsePublicPKCS8Hex:function(t){var v=ASN1HEX;var u=v.getChildIdx;var s=v.getV;var q={};q.algparam=null;var r=u(t,0);if(r.length!=2){throw new Error("outer DERSequence shall have 2 elements: "+r.length)}var w=r[0];if(t.substr(w,2)!="30"){throw new Error("malformed PKCS8 public key(code:001)")}var p=u(t,w);if(p.length!=2){throw new Error("malformed PKCS8 public key(code:002)")}if(t.substr(p[0],2)!="06"){throw new Error("malformed PKCS8 public key(code:003)")}q.algoid=s(t,p[0]);if(t.substr(p[1],2)=="06"){q.algparam=s(t,p[1])}else{if(t.substr(p[1],2)=="30"){q.algparam={};q.algparam.p=v.getVbyList(t,p[1],[0],"02");q.algparam.q=v.getVbyList(t,p[1],[1],"02");q.algparam.g=v.getVbyList(t,p[1],[2],"02")}}if(t.substr(r[1],2)!="03"){throw new Error("malformed PKCS8 public key(code:004)")}q.key=s(t,r[1]).substr(2);return q},}}();KEYUTIL.getKey=function(l,k,n){var G=ASN1HEX,L=G.getChildIdx,v=G.getV,d=G.getVbyList,c=KJUR.crypto,i=c.ECDSA,C=c.DSA,w=RSAKey,M=pemtohex,F=KEYUTIL;if(typeof w!="undefined"&&l instanceof w){return l}if(typeof i!="undefined"&&l instanceof i){return l}if(typeof C!="undefined"&&l instanceof C){return l}if(l.curve!==undefined&&l.xy!==undefined&&l.d===undefined){return new i({pub:l.xy,curve:l.curve})}if(l.curve!==undefined&&l.d!==undefined){return new i({prv:l.d,curve:l.curve})}if(l.kty===undefined&&l.n!==undefined&&l.e!==undefined&&l.d===undefined){var P=new w();P.setPublic(l.n,l.e);return P}if(l.kty===undefined&&l.n!==undefined&&l.e!==undefined&&l.d!==undefined&&l.p!==undefined&&l.q!==undefined&&l.dp!==undefined&&l.dq!==undefined&&l.co!==undefined&&l.qi===undefined){var P=new w();P.setPrivateEx(l.n,l.e,l.d,l.p,l.q,l.dp,l.dq,l.co);return P}if(l.kty===undefined&&l.n!==undefined&&l.e!==undefined&&l.d!==undefined&&l.p===undefined){var P=new w();P.setPrivate(l.n,l.e,l.d);return P}if(l.p!==undefined&&l.q!==undefined&&l.g!==undefined&&l.y!==undefined&&l.x===undefined){var P=new C();P.setPublic(l.p,l.q,l.g,l.y);return P}if(l.p!==undefined&&l.q!==undefined&&l.g!==undefined&&l.y!==undefined&&l.x!==undefined){var P=new C();P.setPrivate(l.p,l.q,l.g,l.y,l.x);return P}if(l.kty==="RSA"&&l.n!==undefined&&l.e!==undefined&&l.d===undefined){var P=new w();P.setPublic(b64utohex(l.n),b64utohex(l.e));return P}if(l.kty==="RSA"&&l.n!==undefined&&l.e!==undefined&&l.d!==undefined&&l.p!==undefined&&l.q!==undefined&&l.dp!==undefined&&l.dq!==undefined&&l.qi!==undefined){var P=new w();P.setPrivateEx(b64utohex(l.n),b64utohex(l.e),b64utohex(l.d),b64utohex(l.p),b64utohex(l.q),b64utohex(l.dp),b64utohex(l.dq),b64utohex(l.qi));return P}if(l.kty==="RSA"&&l.n!==undefined&&l.e!==undefined&&l.d!==undefined){var P=new w();P.setPrivate(b64utohex(l.n),b64utohex(l.e),b64utohex(l.d));return P}if(l.kty==="EC"&&l.crv!==undefined&&l.x!==undefined&&l.y!==undefined&&l.d===undefined){var j=new i({curve:l.crv});var t=j.ecparams.keycharlen;var B=("0000000000"+b64utohex(l.x)).slice(-t);var z=("0000000000"+b64utohex(l.y)).slice(-t);var u="04"+B+z;j.setPublicKeyHex(u);return j}if(l.kty==="EC"&&l.crv!==undefined&&l.x!==undefined&&l.y!==undefined&&l.d!==undefined){var j=new i({curve:l.crv});var t=j.ecparams.keycharlen;var B=("0000000000"+b64utohex(l.x)).slice(-t);var z=("0000000000"+b64utohex(l.y)).slice(-t);var u="04"+B+z;var b=("0000000000"+b64utohex(l.d)).slice(-t);j.setPublicKeyHex(u);j.setPrivateKeyHex(b);return j}if(n==="pkcs5prv"){var J=l,G=ASN1HEX,N,P;N=L(J,0);if(N.length===9){P=new w();P.readPKCS5PrvKeyHex(J)}else{if(N.length===6){P=new C();P.readPKCS5PrvKeyHex(J)}else{if(N.length>2&&J.substr(N[1],2)==="04"){P=new i();P.readPKCS5PrvKeyHex(J)}else{throw new Error("unsupported PKCS#1/5 hexadecimal key")}}}return P}if(n==="pkcs8prv"){var P=F.getKeyFromPlainPrivatePKCS8Hex(l);return P}if(n==="pkcs8pub"){return F._getKeyFromPublicPKCS8Hex(l)}if(n==="x509pub"){return X509.getPublicKeyFromCertHex(l)}if(l.indexOf("-END CERTIFICATE-",0)!=-1||l.indexOf("-END X509 CERTIFICATE-",0)!=-1||l.indexOf("-END TRUSTED CERTIFICATE-",0)!=-1){return X509.getPublicKeyFromCertPEM(l)}if(l.indexOf("-END PUBLIC KEY-")!=-1){var O=pemtohex(l,"PUBLIC KEY");return F._getKeyFromPublicPKCS8Hex(O)}if(l.indexOf("-END RSA PRIVATE KEY-")!=-1&&l.indexOf("4,ENCRYPTED")==-1){var m=M(l,"RSA PRIVATE KEY");return F.getKey(m,null,"pkcs5prv")}if(l.indexOf("-END DSA PRIVATE KEY-")!=-1&&l.indexOf("4,ENCRYPTED")==-1){var I=M(l,"DSA PRIVATE KEY");var E=d(I,0,[1],"02");var D=d(I,0,[2],"02");var K=d(I,0,[3],"02");var r=d(I,0,[4],"02");var s=d(I,0,[5],"02");var P=new C();P.setPrivate(new BigInteger(E,16),new BigInteger(D,16),new BigInteger(K,16),new BigInteger(r,16),new BigInteger(s,16));return P}if(l.indexOf("-END EC PRIVATE KEY-")!=-1&&l.indexOf("4,ENCRYPTED")==-1){var m=M(l,"EC PRIVATE KEY");return F.getKey(m,null,"pkcs5prv")}if(l.indexOf("-END PRIVATE KEY-")!=-1){return F.getKeyFromPlainPrivatePKCS8PEM(l)}if(l.indexOf("-END RSA PRIVATE KEY-")!=-1&&l.indexOf("4,ENCRYPTED")!=-1){var o=F.getDecryptedKeyHex(l,k);var H=new RSAKey();H.readPKCS5PrvKeyHex(o);return H}if(l.indexOf("-END EC PRIVATE KEY-")!=-1&&l.indexOf("4,ENCRYPTED")!=-1){var I=F.getDecryptedKeyHex(l,k);var P=d(I,0,[1],"04");var f=d(I,0,[2,0],"06");var A=d(I,0,[3,0],"03").substr(2);var e="";if(KJUR.crypto.OID.oidhex2name[f]!==undefined){e=KJUR.crypto.OID.oidhex2name[f]}else{throw new Error("undefined OID(hex) in KJUR.crypto.OID: "+f)}var j=new i({curve:e});j.setPublicKeyHex(A);j.setPrivateKeyHex(P);j.isPublic=false;return j}if(l.indexOf("-END DSA PRIVATE KEY-")!=-1&&l.indexOf("4,ENCRYPTED")!=-1){var I=F.getDecryptedKeyHex(l,k);var E=d(I,0,[1],"02");var D=d(I,0,[2],"02");var K=d(I,0,[3],"02");var r=d(I,0,[4],"02");var s=d(I,0,[5],"02");var P=new C();P.setPrivate(new BigInteger(E,16),new BigInteger(D,16),new BigInteger(K,16),new BigInteger(r,16),new BigInteger(s,16));return P}if(l.indexOf("-END ENCRYPTED PRIVATE KEY-")!=-1){return F.getKeyFromEncryptedPKCS8PEM(l,k)}throw new Error("not supported argument")};KEYUTIL.generateKeypair=function(a,c){if(a=="RSA"){var b=c;var h=new RSAKey();h.generate(b,"10001");h.isPrivate=true;h.isPublic=true;var f=new RSAKey();var e=h.n.toString(16);var i=h.e.toString(16);f.setPublic(e,i);f.isPrivate=false;f.isPublic=true;var k={};k.prvKeyObj=h;k.pubKeyObj=f;return k}else{if(a=="EC"){var d=c;var g=new KJUR.crypto.ECDSA({curve:d});var j=g.generateKeyPairHex();var h=new KJUR.crypto.ECDSA({curve:d});h.setPublicKeyHex(j.ecpubhex);h.setPrivateKeyHex(j.ecprvhex);h.isPrivate=true;h.isPublic=false;var f=new KJUR.crypto.ECDSA({curve:d});f.setPublicKeyHex(j.ecpubhex);f.isPrivate=false;f.isPublic=true;var k={};k.prvKeyObj=h;k.pubKeyObj=f;return k}else{throw new Error("unknown algorithm: "+a)}}};KEYUTIL.getPEM=function(b,D,y,m,q,j){var F=KJUR,k=F.asn1,z=k.DERObjectIdentifier,f=k.DERInteger,l=k.ASN1Util.newObject,a=k.x509,C=a.SubjectPublicKeyInfo,e=F.crypto,u=e.DSA,r=e.ECDSA,n=RSAKey;function A(s){var H=l({seq:[{"int":0},{"int":{bigint:s.n}},{"int":s.e},{"int":{bigint:s.d}},{"int":{bigint:s.p}},{"int":{bigint:s.q}},{"int":{bigint:s.dmp1}},{"int":{bigint:s.dmq1}},{"int":{bigint:s.coeff}}]});return H}function B(H){var s=l({seq:[{"int":1},{octstr:{hex:H.prvKeyHex}},{tag:["a0",true,{oid:{name:H.curveName}}]},{tag:["a1",true,{bitstr:{hex:"00"+H.pubKeyHex}}]}]});return s}function x(s){var H=l({seq:[{"int":0},{"int":{bigint:s.p}},{"int":{bigint:s.q}},{"int":{bigint:s.g}},{"int":{bigint:s.y}},{"int":{bigint:s.x}}]});return H}if(((n!==undefined&&b instanceof n)||(u!==undefined&&b instanceof u)||(r!==undefined&&b instanceof r))&&b.isPublic==true&&(D===undefined||D=="PKCS8PUB")){var E=new C(b);var w=E.tohex();return hextopem(w,"PUBLIC KEY")}if(D=="PKCS1PRV"&&n!==undefined&&b instanceof n&&(y===undefined||y==null)&&b.isPrivate==true){var E=A(b);var w=E.tohex();return hextopem(w,"RSA PRIVATE KEY")}if(D=="PKCS1PRV"&&r!==undefined&&b instanceof r&&(y===undefined||y==null)&&b.isPrivate==true){var i=new z({name:b.curveName});var v=i.tohex();var h=B(b);var t=h.tohex();var p="";p+=hextopem(v,"EC PARAMETERS");p+=hextopem(t,"EC PRIVATE KEY");return p}if(D=="PKCS1PRV"&&u!==undefined&&b instanceof u&&(y===undefined||y==null)&&b.isPrivate==true){var E=x(b);var w=E.tohex();return hextopem(w,"DSA PRIVATE KEY")}if(D=="PKCS5PRV"&&n!==undefined&&b instanceof n&&(y!==undefined&&y!=null)&&b.isPrivate==true){var E=A(b);var w=E.tohex();if(m===undefined){m="DES-EDE3-CBC"}return this.getEncryptedPKCS5PEMFromPrvKeyHex("RSA",w,y,m,j)}if(D=="PKCS5PRV"&&r!==undefined&&b instanceof r&&(y!==undefined&&y!=null)&&b.isPrivate==true){var E=B(b);var w=E.tohex();if(m===undefined){m="DES-EDE3-CBC"}return this.getEncryptedPKCS5PEMFromPrvKeyHex("EC",w,y,m,j)}if(D=="PKCS5PRV"&&u!==undefined&&b instanceof u&&(y!==undefined&&y!=null)&&b.isPrivate==true){var E=x(b);var w=E.tohex();if(m===undefined){m="DES-EDE3-CBC"}return this.getEncryptedPKCS5PEMFromPrvKeyHex("DSA",w,y,m,j)}var o=function(H,s){var J=c(H,s);var I=new l({seq:[{seq:[{oid:{name:"pkcs5PBES2"}},{seq:[{seq:[{oid:{name:"pkcs5PBKDF2"}},{seq:[{octstr:{hex:J.pbkdf2Salt}},{"int":J.pbkdf2Iter}]}]},{seq:[{oid:{name:"des-EDE3-CBC"}},{octstr:{hex:J.encryptionSchemeIV}}]}]}]},{octstr:{hex:J.ciphertext}}]});return I.tohex()};var c=function(O,P){var I=100;var N=CryptoJS.lib.WordArray.random(8);var M="DES-EDE3-CBC";var s=CryptoJS.lib.WordArray.random(8);var J=CryptoJS.PBKDF2(P,N,{keySize:192/32,iterations:I});var K=CryptoJS.enc.Hex.parse(O);var L=CryptoJS.TripleDES.encrypt(K,J,{iv:s})+"";var H={};H.ciphertext=L;H.pbkdf2Salt=CryptoJS.enc.Hex.stringify(N);H.pbkdf2Iter=I;H.encryptionSchemeAlg=M;H.encryptionSchemeIV=CryptoJS.enc.Hex.stringify(s);return H};if(D=="PKCS8PRV"&&n!=undefined&&b instanceof n&&b.isPrivate==true){var g=A(b);var d=g.tohex();var E=l({seq:[{"int":0},{seq:[{oid:{name:"rsaEncryption"}},{"null":true}]},{octstr:{hex:d}}]});var w=E.tohex();if(y===undefined||y==null){return hextopem(w,"PRIVATE KEY")}else{var t=o(w,y);return hextopem(t,"ENCRYPTED PRIVATE KEY")}}if(D=="PKCS8PRV"&&r!==undefined&&b instanceof r&&b.isPrivate==true){var G={seq:[{"int":1},{octstr:{hex:b.prvKeyHex}}]};if(typeof b.pubKeyHex=="string"){G.seq.push({tag:["a1",true,{bitstr:{hex:"00"+b.pubKeyHex}}]})}var g=new l(G);var d=g.tohex();var E=l({seq:[{"int":0},{seq:[{oid:{name:"ecPublicKey"}},{oid:{name:b.curveName}}]},{octstr:{hex:d}}]});var w=E.tohex();if(y===undefined||y==null){return hextopem(w,"PRIVATE KEY")}else{var t=o(w,y);return hextopem(t,"ENCRYPTED PRIVATE KEY")}}if(D=="PKCS8PRV"&&u!==undefined&&b instanceof u&&b.isPrivate==true){var g=new f({bigint:b.x});var d=g.tohex();var E=l({seq:[{"int":0},{seq:[{oid:{name:"dsa"}},{seq:[{"int":{bigint:b.p}},{"int":{bigint:b.q}},{"int":{bigint:b.g}}]}]},{octstr:{hex:d}}]});var w=E.tohex();if(y===undefined||y==null){return hextopem(w,"PRIVATE KEY")}else{var t=o(w,y);return hextopem(t,"ENCRYPTED PRIVATE KEY")}}throw new Error("unsupported object nor format")};KEYUTIL.getKeyFromCSRPEM=function(b){var a=pemtohex(b,"CERTIFICATE REQUEST");var c=KEYUTIL.getKeyFromCSRHex(a);return c};KEYUTIL.getKeyFromCSRHex=function(a){var c=KEYUTIL.parseCSRHex(a);var b=KEYUTIL.getKey(c.p8pubkeyhex,null,"pkcs8pub");return b};KEYUTIL.parseCSRHex=function(d){var i=ASN1HEX;var f=i.getChildIdx;var c=i.getTLV;var b={};var g=d;if(g.substr(0,2)!="30"){throw new Error("malformed CSR(code:001)")}var e=f(g,0);if(e.length<1){throw new Error("malformed CSR(code:002)")}if(g.substr(e[0],2)!="30"){throw new Error("malformed CSR(code:003)")}var a=f(g,e[0]);if(a.length<3){throw new Error("malformed CSR(code:004)")}b.p8pubkeyhex=c(g,a[2]);return b};KEYUTIL.getKeyID=function(f){var c=KEYUTIL;var e=ASN1HEX;if(typeof f==="string"&&f.indexOf("BEGIN ")!=-1){f=c.getKey(f)}var d=pemtohex(c.getPEM(f));var b=e.getIdxbyList(d,0,[1]);var a=e.getV(d,b).substring(2);return KJUR.crypto.Util.hashHex(a,"sha1")};KEYUTIL.getJWK=function(d,h,g,b,f){var i;var k={};var e;var c=KJUR.crypto.Util.hashHex;if(typeof d=="string"){i=KEYUTIL.getKey(d);if(d.indexOf("CERTIFICATE")!=-1){e=pemtohex(d)}}else{if(typeof d=="object"){if(d instanceof X509){i=d.getPublicKey();e=d.hex}else{i=d}}else{throw new Error("unsupported keyinfo type")}}if(i instanceof RSAKey&&i.isPrivate){k.kty="RSA";k.n=hextob64u(i.n.toString(16));k.e=hextob64u(i.e.toString(16));k.d=hextob64u(i.d.toString(16));k.p=hextob64u(i.p.toString(16));k.q=hextob64u(i.q.toString(16));k.dp=hextob64u(i.dmp1.toString(16));k.dq=hextob64u(i.dmq1.toString(16));k.qi=hextob64u(i.coeff.toString(16))}else{if(i instanceof RSAKey&&i.isPublic){k.kty="RSA";k.n=hextob64u(i.n.toString(16));k.e=hextob64u(i.e.toString(16))}else{if(i instanceof KJUR.crypto.ECDSA&&i.isPrivate){var a=i.getShortNISTPCurveName();if(a!=="P-256"&&a!=="P-384"&&a!=="P-521"){throw new Error("unsupported curve name for JWT: "+a)}var j=i.getPublicKeyXYHex();k.kty="EC";k.crv=a;k.x=hextob64u(j.x);k.y=hextob64u(j.y);k.d=hextob64u(i.prvKeyHex)}else{if(i instanceof KJUR.crypto.ECDSA&&i.isPublic){var a=i.getShortNISTPCurveName();if(a!=="P-256"&&a!=="P-384"&&a!=="P-521"){throw new Error("unsupported curve name for JWT: "+a)}var j=i.getPublicKeyXYHex();k.kty="EC";k.crv=a;k.x=hextob64u(j.x);k.y=hextob64u(j.y)}}}}if(k.kty==undefined){throw new Error("unsupported keyinfo")}if((!i.isPrivate)&&h!=true){k.kid=KJUR.jws.JWS.getJWKthumbprint(k)}if(e!=undefined&&g!=true){k.x5c=[hex2b64(e)]}if(e!=undefined&&b!=true){k.x5t=b64tob64u(hex2b64(c(e,"sha1")))}if(e!=undefined&&f!=true){k["x5t#S256"]=b64tob64u(hex2b64(c(e,"sha256")))}return k};KEYUTIL.getJWKFromKey=function(a){return KEYUTIL.getJWK(a,true,true,true,true)}; +RSAKey.getPosArrayOfChildrenFromHex=function(a){return ASN1HEX.getChildIdx(a,0)};RSAKey.getHexValueArrayOfChildrenFromHex=function(f){var n=ASN1HEX;var i=n.getV;var k=RSAKey.getPosArrayOfChildrenFromHex(f);var e=i(f,k[0]);var j=i(f,k[1]);var b=i(f,k[2]);var c=i(f,k[3]);var h=i(f,k[4]);var g=i(f,k[5]);var m=i(f,k[6]);var l=i(f,k[7]);var d=i(f,k[8]);var k=new Array();k.push(e,j,b,c,h,g,m,l,d);return k};RSAKey.prototype.readPrivateKeyFromPEMString=function(d){var c=pemtohex(d);var b=RSAKey.getHexValueArrayOfChildrenFromHex(c);this.setPrivateEx(b[1],b[2],b[3],b[4],b[5],b[6],b[7],b[8])};RSAKey.prototype.readPKCS5PrvKeyHex=function(c){var b=RSAKey.getHexValueArrayOfChildrenFromHex(c);this.setPrivateEx(b[1],b[2],b[3],b[4],b[5],b[6],b[7],b[8])};RSAKey.prototype.readPKCS8PrvKeyHex=function(e){var c,i,k,b,a,f,d,j;var m=ASN1HEX;var l=m.getVbyListEx;if(m.isASN1HEX(e)===false){throw new Error("not ASN.1 hex string")}try{c=l(e,0,[2,0,1],"02");i=l(e,0,[2,0,2],"02");k=l(e,0,[2,0,3],"02");b=l(e,0,[2,0,4],"02");a=l(e,0,[2,0,5],"02");f=l(e,0,[2,0,6],"02");d=l(e,0,[2,0,7],"02");j=l(e,0,[2,0,8],"02")}catch(g){throw new Error("malformed PKCS#8 plain RSA private key")}this.setPrivateEx(c,i,k,b,a,f,d,j)};RSAKey.prototype.readPKCS5PubKeyHex=function(c){var e=ASN1HEX;var b=e.getV;if(e.isASN1HEX(c)===false){throw new Error("keyHex is not ASN.1 hex string")}var a=e.getChildIdx(c,0);if(a.length!==2||c.substr(a[0],2)!=="02"||c.substr(a[1],2)!=="02"){throw new Error("wrong hex for PKCS#5 public key")}var f=b(c,a[0]);var d=b(c,a[1]);this.setPublic(f,d)};RSAKey.prototype.readPKCS8PubKeyHex=function(b){var c=ASN1HEX;if(c.isASN1HEX(b)===false){throw new Error("not ASN.1 hex string")}if(c.getTLVbyListEx(b,0,[0,0])!=="06092a864886f70d010101"){throw new Error("not PKCS8 RSA public key")}var a=c.getTLVbyListEx(b,0,[1,0]);this.readPKCS5PubKeyHex(a)};RSAKey.prototype.readCertPubKeyHex=function(b,d){var a,c;a=new X509();a.readCertHex(b);c=a.getPublicKeyHex();this.readPKCS8PubKeyHex(c)}; +var _RE_HEXDECONLY=new RegExp("[^0-9a-f]","gi");function _rsasign_getHexPaddedDigestInfoForString(d,e,a){var b=function(f){return KJUR.crypto.Util.hashString(f,a)};var c=b(d);return KJUR.crypto.Util.getPaddedDigestInfoHex(c,a,e)}function _zeroPaddingOfSignature(e,d){var c="";var a=d/4-e.length;for(var b=0;b>24,(d&16711680)>>16,(d&65280)>>8,d&255]))));d+=1}return b}RSAKey.prototype.signPSS=function(e,a,d){var c=function(f){return KJUR.crypto.Util.hashHex(f,a)};var b=c(rstrtohex(e));if(d===undefined){d=-1}return this.signWithMessageHashPSS(b,a,d)};RSAKey.prototype.signWithMessageHashPSS=function(l,a,k){var b=hextorstr(l);var g=b.length;var m=this.n.bitLength()-1;var c=Math.ceil(m/8);var d;var o=function(i){return KJUR.crypto.Util.hashHex(i,a)};if(k===-1||k===undefined){k=g}else{if(k===-2){k=c-g-2}else{if(k<-2){throw new Error("invalid salt length")}}}if(c<(g+k+2)){throw new Error("data too long")}var f="";if(k>0){f=new Array(k);new SecureRandom().nextBytes(f);f=String.fromCharCode.apply(String,f)}var n=hextorstr(o(rstrtohex("\x00\x00\x00\x00\x00\x00\x00\x00"+b+f)));var j=[];for(d=0;d>(8*c-m))&255;q[0]&=~p;for(d=0;dk){return false}var j=this.doPublic(b);var i=j.toString(16);if(i.length+3!=k/4){return false}var e=i.replace(/^1f+00/,"");var g=_rsasign_getAlgNameAndHashFromHexDisgestInfo(e);if(g.length==0){return false}var d=g[0];var h=g[1];var a=function(m){return KJUR.crypto.Util.hashString(m,d)};var c=a(f);return(h==c)};RSAKey.prototype.verifyWithMessageHash=function(e,a){if(a.length!=Math.ceil(this.n.bitLength()/4)){return false}var b=parseBigInt(a,16);if(b.bitLength()>this.n.bitLength()){return 0}var h=this.doPublic(b);var g=h.toString(16).replace(/^1f+00/,"");var c=_rsasign_getAlgNameAndHashFromHexDisgestInfo(g);if(c.length==0){return false}var d=c[0];var f=c[1];return(f==e)};RSAKey.prototype.verifyPSS=function(c,b,a,f){var e=function(g){return KJUR.crypto.Util.hashHex(g,a)};var d=e(rstrtohex(c));if(f===undefined){f=-1}return this.verifyWithMessageHashPSS(d,b,a,f)};RSAKey.prototype.verifyWithMessageHashPSS=function(f,s,l,c){if(s.length!=Math.ceil(this.n.bitLength()/4)){return false}var k=new BigInteger(s,16);var r=function(i){return KJUR.crypto.Util.hashHex(i,l)};var j=hextorstr(f);var h=j.length;var g=this.n.bitLength()-1;var m=Math.ceil(g/8);var q;if(c===-1||c===undefined){c=h}else{if(c===-2){c=m-h-2}else{if(c<-2){throw new Error("invalid salt length")}}}if(m<(h+c+2)){throw new Error("data too long")}var a=this.doPublic(k).toByteArray();for(q=0;q>(8*m-g))&255;if((d.charCodeAt(0)&p)!==0){throw new Error("bits beyond keysize not zero")}var n=pss_mgf1_str(e,d.length,r);var o=[];for(q=0;q0){return z}return undefined}catch(B){return undefined}};this._asn1ToNoticeRef=function(F){try{var A={};var B=aryval(F,"seq");for(var D=0;D0){return A}return undefined}catch(C){return undefined}};this._asn1ToNoticeNum=function(E){try{var A=aryval(E,"seq");var z=[];for(var C=0;C1){var G=b(C,B[1]);var A=this.getGeneralName(G);if(A.uri!=undefined){z.uri=A.uri}}if(B.length>2){var D=b(C,B[2]);if(D=="0101ff"){z.reqauth=true}if(D=="010100"){z.reqauth=false}}return z};this.getExtSubjectDirectoryAttributes=function(I,H){if(I===undefined&&H===undefined){var B=this.getExtInfo("subjectDirectoryAttributes");if(B===undefined){return undefined}I=b(this.hex,B.vidx);H=B.critical}var J={extname:"subjectDirectoryAttributes"};if(H){J.critical=true}try{var z=j(I);var D=[];for(var E=0;E0){z.ext=this.getExtParamArray()}z.sighex=this.getSignatureValueHex();if(A.tbshex==true){z.tbshex=a(this.hex,0,[0])}if(A.nodnarray==true){delete z.issuer.array;delete z.subject.array}return z};this.getExtParamArray=function(A){if(A==undefined){var C=f(this.hex,0,[0,"[3]"]);if(C!=-1){A=q(this.hex,0,[0,"[3]",0],"30")}}var z=[];var B=s(A,0);for(var D=0;D0){var b=":"+n.join(":")+":";if(b.indexOf(":"+k+":")==-1){throw"algorithm '"+k+"' not accepted in the list"}}if(k!="none"&&B===null){throw"key shall be specified to verify."}if(typeof B=="string"&&B.indexOf("-----BEGIN ")!=-1){B=KEYUTIL.getKey(B)}if(z=="RS"||z=="PS"){if(!(B instanceof m)){throw"key shall be a RSAKey obj for RS* and PS* algs"}}if(z=="ES"){if(!(B instanceof p)){throw"key shall be a ECDSA obj for ES* algs"}}if(k=="none"){}var u=null;if(t.jwsalg2sigalg[l.alg]===undefined){throw"unsupported alg name: "+k}else{u=t.jwsalg2sigalg[k]}if(u=="none"){throw"not supported"}else{if(u.substr(0,4)=="Hmac"){var o=null;if(B===undefined){throw"hexadecimal key shall be specified for HMAC"}var j=new s({alg:u,pass:B});j.updateString(c);o=j.doFinal();return A==o}else{if(u.indexOf("withECDSA")!=-1){var h=null;try{h=p.concatSigToASN1Sig(A)}catch(v){return false}var g=new d({alg:u});g.init(B);g.updateString(c);return g.verify(h)}else{var g=new d({alg:u});g.init(B);g.updateString(c);return g.verify(A)}}}};KJUR.jws.JWS.parse=function(g){var c=g.split(".");var b={};var f,e,d;if(c.length!=2&&c.length!=3){throw"malformed sJWS: wrong number of '.' splitted elements"}f=c[0];e=c[1];if(c.length==3){d=c[2]}b.headerObj=KJUR.jws.JWS.readSafeJSONString(b64utoutf8(f));b.payloadObj=KJUR.jws.JWS.readSafeJSONString(b64utoutf8(e));b.headerPP=JSON.stringify(b.headerObj,null," ");if(b.payloadObj==null){b.payloadPP=b64utoutf8(e)}else{b.payloadPP=JSON.stringify(b.payloadObj,null," ")}if(d!==undefined){b.sigHex=b64utohex(d)}return b};KJUR.jws.JWS.verifyJWT=function(e,l,r){var d=KJUR,j=d.jws,o=j.JWS,n=o.readSafeJSONString,p=o.inArray,f=o.includedArray;if(!isBase64URLDot(e)){return false}var k=e.split(".");if(k.length!=3){return false}var c=k[0];var i=k[1];var q=c+"."+i;var m=b64utohex(k[2]);var h=n(b64utoutf8(c));var g=n(b64utoutf8(i));if(h.alg===undefined){return false}if(r.alg===undefined){throw"acceptField.alg shall be specified"}if(!p(h.alg,r.alg)){return false}if(g.iss!==undefined&&typeof r.iss==="object"){if(!p(g.iss,r.iss)){return false}}if(g.sub!==undefined&&typeof r.sub==="object"){if(!p(g.sub,r.sub)){return false}}if(g.aud!==undefined&&typeof r.aud==="object"){if(typeof g.aud=="string"){if(!p(g.aud,r.aud)){return false}}else{if(typeof g.aud=="object"){if(!f(g.aud,r.aud)){return false}}}}var b=j.IntDate.getNow();if(r.verifyAt!==undefined&&typeof r.verifyAt==="number"){b=r.verifyAt}if(r.gracePeriod===undefined||typeof r.gracePeriod!=="number"){r.gracePeriod=0}if(g.exp!==undefined&&typeof g.exp=="number"){if(g.exp+r.gracePeriodl){this.aHeader.pop()}if(this.aSignature.length>l){this.aSignature.pop()}throw"addSignature failed: "+i}};this.verifyAll=function(h){if(this.aHeader.length!==h.length||this.aSignature.length!==h.length){return false}for(var g=0;g0){this.aHeader=g.headers}else{throw"malformed header"}if(typeof g.payload==="string"){this.sPayload=g.payload}else{throw"malformed signatures"}if(g.signatures.length>0){this.aSignature=g.signatures}else{throw"malformed signatures"}}catch(e){throw"malformed JWS-JS JSON object: "+e}}};this.getJSON=function(){return{headers:this.aHeader,payload:this.sPayload,signatures:this.aSignature}};this.isEmpty=function(){if(this.aHeader.length==0){return 1}return 0}}; +/* eslint-enable no-use-before-define */ From 685964d996d5ed4a46bfa17f9e80530e11c33fef Mon Sep 17 00:00:00 2001 From: barduinor Date: Wed, 20 Sep 2023 16:35:28 -0400 Subject: [PATCH 15/34] improved pre-script execution conditions to not execute outside of normal box api requests --- src/events/collectionPreReqScript.js | 50 ++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 13 deletions(-) diff --git a/src/events/collectionPreReqScript.js b/src/events/collectionPreReqScript.js index 08cab52..9d5af58 100644 --- a/src/events/collectionPreReqScript.js +++ b/src/events/collectionPreReqScript.js @@ -4,6 +4,30 @@ /* eslint-disable camelcase */ /* eslint-disable object-shorthand */ + +const check_script_execution = () => { + // determine if this script be executed + const req = pm.request + let reqUrl = pm.request.url.protocol + '://' + pm.request.url.host + for (const itemPath of pm.request.url.path) { + reqUrl = reqUrl + '/' + itemPath + } + + // Reject requests where auth type exists + if (pm.request.auth) { return false } + + // black list + if (reqUrl.startsWith(pm.request.url.protocol + '://' + '{{api.box.com}}/oauth2')) { return false } + + // white list + if (reqUrl.startsWith(pm.request.url.protocol + '://' + '{{api.box.com}}')) { return true } + if (reqUrl.startsWith(pm.request.url.protocol + '://' + '{{upload.box.com}}')) { return true } + if (reqUrl.startsWith(pm.request.url.protocol + '://' + '{{dl.boxcloud.com}}')) { return true } + + // reject everything else + return false +} + const check_environment = () => { // check current environment name const env_type = pm.environment.get('box_env_type') @@ -157,15 +181,15 @@ function get_jwt_assertion () { const header = { alg: 'RS512', typ: 'JWT', kid: kid } const claims = - { - iss: iss, - sub: sub, - box_sub_type: box_sub_type, - aud: aud, - jti: jti, - exp: exp, - iat: iat - } + { + iss: iss, + sub: sub, + box_sub_type: box_sub_type, + aud: aud, + jti: jti, + exp: exp, + iat: iat + } const jwt = KJUR.jws.JWS.sign(null, header, claims, private_key) @@ -194,10 +218,10 @@ async function refresh_jwt (assertion) { } const box_postman = () => { - // if authotization type is not null (not inherited) then exit the script - if (pm.request.auth) { return } - // console.info('Collection variables',pm.collectionVariables.toObject()) + // console.info('Request',pm.request) + + if (!check_script_execution()) { return } const env_type = check_environment() @@ -209,7 +233,7 @@ const box_postman = () => { if (is_expired) { switch (env_type) { case EnvType.BEARER: - console.info('can`t refresh bearer token, sending as is...') + console.info('Bearer token can not be refreshed, sending as is...') break case EnvType.OAUTH: /* eslint-disable no-case-declarations */ From 1a38837800ade672bd89d8430b815e00449b79ce Mon Sep 17 00:00:00 2001 From: barduinor Date: Wed, 20 Sep 2023 16:36:22 -0400 Subject: [PATCH 16/34] fix lint --- src/events/collectionPreReqScript.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/events/collectionPreReqScript.js b/src/events/collectionPreReqScript.js index 9d5af58..84fbf02 100644 --- a/src/events/collectionPreReqScript.js +++ b/src/events/collectionPreReqScript.js @@ -7,7 +7,6 @@ const check_script_execution = () => { // determine if this script be executed - const req = pm.request let reqUrl = pm.request.url.protocol + '://' + pm.request.url.host for (const itemPath of pm.request.url.path) { reqUrl = reqUrl + '/' + itemPath From 8aebea879b3e3e4513853be4c1194c3a4c57ef4b Mon Sep 17 00:00:00 2001 From: barduinor Date: Wed, 20 Sep 2023 17:28:32 -0400 Subject: [PATCH 17/34] WIP: adding the new util object to the collection deployment --- src/CollectionAdvanced.js | 2 +- src/CollectionAdvancedUtils.js | 27 +++++++++++++++++++++++++++ src/DeployIncremental.js | 8 +++++++- src/scripts/releaseAdvanced.js | 2 +- 4 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 src/CollectionAdvancedUtils.js diff --git a/src/CollectionAdvanced.js b/src/CollectionAdvanced.js index db17343..92614ff 100644 --- a/src/CollectionAdvanced.js +++ b/src/CollectionAdvanced.js @@ -63,7 +63,7 @@ class CollectionAdvanced extends Collection { // PRIVATE authForEndPoint (endpoint) { - // RB: All endpoints inherit fomr the collection + // RB: All endpoints inherit from the collection return null } diff --git a/src/CollectionAdvancedUtils.js b/src/CollectionAdvancedUtils.js new file mode 100644 index 0000000..e4a7df7 --- /dev/null +++ b/src/CollectionAdvancedUtils.js @@ -0,0 +1,27 @@ +// Utitlity objects specific for Postman Collection +// These are not related with the Box Platform API +// Therefor they are not in the OpenAPI json +// +// These can be injected in using a flag in via the DeploymentIcremental.js script +// and should be invoked in the releaseAdvanced.js script +const Utils = require('./Utils') + +const injectUtils = (localCollection) => { + // insert Utils folder at top level item + localCollection.item.unshift(genFolder('(Utils)', 'Utility scripts for Postman Collection')) + + return localCollection +} + +const genFolder = (name, description) => { + const folder = { + name, + description + } + folder.id = Utils.GenID(JSON.stringify(folder)) + return folder +} + +module.exports = { + injectUtils +} diff --git a/src/DeployIncremental.js b/src/DeployIncremental.js index d28fa82..4b27b76 100644 --- a/src/DeployIncremental.js +++ b/src/DeployIncremental.js @@ -15,9 +15,15 @@ const pmConvert = require('./PostmanCovertions') const pmAPI = require('./postmanAPI') +const injectUtils = require('./CollectionAdvancedUtils').injectUtils const { GenID } = require('./Utils') -const deployIncremental = async (privateRemoteCollectionId, localCollection, publicRemoteCollectionId) => { +const deployIncremental = async (privateRemoteCollectionId, localCollection, publicRemoteCollectionId, withUtils = true) => { + // inject extra Postman objects + if (withUtils) { + localCollection = injectUtils(localCollection) + } + let remoteCollection = await refreshRemoteCollection(privateRemoteCollectionId) console.log('Incremental deployment of collection ', localCollection.info.name) diff --git a/src/scripts/releaseAdvanced.js b/src/scripts/releaseAdvanced.js index 4eace5d..b52873a 100644 --- a/src/scripts/releaseAdvanced.js +++ b/src/scripts/releaseAdvanced.js @@ -9,7 +9,7 @@ const release = async (locale = process.argv[1]) => { const localCollection = JSON.parse(fs.readFileSync(`${OUTPUT_FOLDER}/collection.advanced.${locale}.json`).toString()) const privateRemoteCollectionId = process.env[`PRIVATE_${locale.toUpperCase()}_POSTMAN_COLLECTION_ADVANCED_ID`] const publicRemoteCollectionId = process.env[`PUBLIC_${locale.toUpperCase()}_POSTMAN_COLLECTION_ADVANCED_ID`] - await deployIncremental(privateRemoteCollectionId, localCollection, publicRemoteCollectionId) + await deployIncremental(privateRemoteCollectionId, localCollection, publicRemoteCollectionId, false) } const releaseAll = async () => { From c2c42774cc96537591e99548063f1afb8d1c862e Mon Sep 17 00:00:00 2001 From: barduinor Date: Thu, 21 Sep 2023 12:51:17 -0400 Subject: [PATCH 18/34] WIP: implemented deploymen of utilities folder and sub folders --- src/Collection.js | 5 ++- src/CollectionAdvanced.js | 27 ++++++++++++++- src/CollectionAdvancedUtils.js | 2 +- src/DeployIncremental.js | 60 ++++++++++++++++++++++++++++------ src/scripts/releaseAdvanced.js | 2 +- 5 files changed, 82 insertions(+), 14 deletions(-) diff --git a/src/Collection.js b/src/Collection.js index 66a2d41..81dde79 100644 --- a/src/Collection.js +++ b/src/Collection.js @@ -205,10 +205,13 @@ class Collection { } // create a folder object - createFolder (folderName) { + createFolder (folderName, folderParentId = null, description = null) { const folder = { name: folderName, + folder: folderParentId, + description: description, item: [] + } const folderId = Utils.GenID(JSON.stringify(folder)) folder.id = folderId diff --git a/src/CollectionAdvanced.js b/src/CollectionAdvanced.js index 92614ff..67f58b1 100644 --- a/src/CollectionAdvanced.js +++ b/src/CollectionAdvanced.js @@ -51,17 +51,42 @@ class CollectionAdvanced extends Collection { */ // RB: override process () { - return { + const localCollection = { info: this.getInfo(), item: this.getItems(), event: [this.collectionPreRequest()], variable: this.getVariables(), auth: this.defaultAuth() } + + // RB: inject utilities + this.injectUtilities(localCollection) + + return localCollection } // PRIVATE + injectUtilities (localCollection) { + // insert Utils folder at top level item + const folderUtilities = this.createFolder('(Utilities)', null, 'Utility scripts for Postman Collection') + localCollection.item.unshift(folderUtilities) + + // insert create environment into Utils folder + const folderCreateEnvironments = this.createFolder('Create Environments', folderUtilities.id, 'Utility scripts for Postman Collection') + localCollection.item.splice(1, 0, folderCreateEnvironments) + + // insert test environment into Utils folder + const folderTestEnvironments = this.createFolder('Test Environments', folderUtilities.id, 'Utility scripts for Postman Collection') + localCollection.item.splice(2, 0, folderTestEnvironments) + + // insert Authorixe OAuth Box App Helper into Utils folder + const folderAuthorizeOAuthBoxAppHelper = this.createFolder('Authorize OAuth Box App Helper', folderUtilities.id, 'Utility scripts for Postman Collection') + localCollection.item.splice(3, 0, folderAuthorizeOAuthBoxAppHelper) + + return localCollection + } + authForEndPoint (endpoint) { // RB: All endpoints inherit from the collection return null diff --git a/src/CollectionAdvancedUtils.js b/src/CollectionAdvancedUtils.js index e4a7df7..234e96f 100644 --- a/src/CollectionAdvancedUtils.js +++ b/src/CollectionAdvancedUtils.js @@ -8,7 +8,7 @@ const Utils = require('./Utils') const injectUtils = (localCollection) => { // insert Utils folder at top level item - localCollection.item.unshift(genFolder('(Utils)', 'Utility scripts for Postman Collection')) + localCollection.item.unshift(genFolder('(Utilities)', 'Utility scripts for Postman Collection')) return localCollection } diff --git a/src/DeployIncremental.js b/src/DeployIncremental.js index 4b27b76..f44b2b4 100644 --- a/src/DeployIncremental.js +++ b/src/DeployIncremental.js @@ -15,15 +15,9 @@ const pmConvert = require('./PostmanCovertions') const pmAPI = require('./postmanAPI') -const injectUtils = require('./CollectionAdvancedUtils').injectUtils const { GenID } = require('./Utils') -const deployIncremental = async (privateRemoteCollectionId, localCollection, publicRemoteCollectionId, withUtils = true) => { - // inject extra Postman objects - if (withUtils) { - localCollection = injectUtils(localCollection) - } - +const deployIncremental = async (privateRemoteCollectionId, localCollection, publicRemoteCollectionId) => { let remoteCollection = await refreshRemoteCollection(privateRemoteCollectionId) console.log('Incremental deployment of collection ', localCollection.info.name) @@ -273,10 +267,34 @@ async function mergeRequests (remoteCollection, localCollection) { // loop folders for (const localFolder of localFoldersRequest) { - const remoteRequests = remoteFoldersRequest.find(remoteFolder => remoteFolder.id === localFolder.id).item + // original code + // const remoteRequests = remoteFoldersRequest.find(remoteFolder => remoteFolder.id === localFolder.id).item + // const localRequests = localFolder.item + // + // need to handle the case where the folder is empty + // in that case the item property is undefined + const remoteRemoteFolder = remoteFoldersRequest.find(remoteFolder => ((remoteFolder.id === localFolder.id))) + + // subfolders exist in the local collection as root folders + // but in the remote collection they are in the parent folder + // so we need to handle the case where the subfolder + // exists as a root element in the local collection + // but not in the remote collection + if (!remoteRemoteFolder) { + continue + } + + // handle undifined items + remoteRemoteFolder.item = remoteRemoteFolder.item || [] + + // filter out anything that is not a request + remoteRemoteFolder.item = remoteRemoteFolder.item.filter(request => request.request) + + const remoteRequests = remoteRemoteFolder.item + const localRequests = localFolder.item - // create new requests + // Identify old and new requests const newRequests = localRequests.filter(localRequest => !remoteRequests.find(remoteRequest => remoteRequest.id === localRequest.id)) const oldRequests = remoteRequests.filter(remoteRequest => !localRequests.find(localRequest => localRequest.id === remoteRequest.id)) @@ -350,8 +368,30 @@ async function mergeResponses (remoteCollection, localCollection) { let anyResponseHasChanged = false // loop folders for (const localFolder of localFoldersRequest) { - const remoteRequests = remoteFoldersRequest.find(remoteFolder => remoteFolder.id === localFolder.id).item + // const remoteRequests = remoteFoldersRequest.find(remoteFolder => remoteFolder.id === localFolder.id).item + // need to handle the case where the folder is empty + // in that case the item property is undefined + const remoteRemoteFolder = remoteFoldersRequest.find(remoteFolder => ((remoteFolder.id === localFolder.id))) + + // subfolders exist in the local collection as root folders + // but in the remote collection they are in the parent folder + // so we need to handle the case where the subfolder + // exists as a root element in the local collection + // but not in the remote collection + if (!remoteRemoteFolder) { + continue + } + + // handle undifined items + remoteRemoteFolder.item = remoteRemoteFolder.item || [] + + // filter out anything that is not a request + remoteRemoteFolder.item = remoteRemoteFolder.item.filter(request => request.request) + + const remoteRequests = remoteRemoteFolder.item + const localRequests = localFolder.item + console.log(' In Folder: ', localFolder.name) // loop requests for (const localRequest of localRequests) { diff --git a/src/scripts/releaseAdvanced.js b/src/scripts/releaseAdvanced.js index b52873a..4eace5d 100644 --- a/src/scripts/releaseAdvanced.js +++ b/src/scripts/releaseAdvanced.js @@ -9,7 +9,7 @@ const release = async (locale = process.argv[1]) => { const localCollection = JSON.parse(fs.readFileSync(`${OUTPUT_FOLDER}/collection.advanced.${locale}.json`).toString()) const privateRemoteCollectionId = process.env[`PRIVATE_${locale.toUpperCase()}_POSTMAN_COLLECTION_ADVANCED_ID`] const publicRemoteCollectionId = process.env[`PUBLIC_${locale.toUpperCase()}_POSTMAN_COLLECTION_ADVANCED_ID`] - await deployIncremental(privateRemoteCollectionId, localCollection, publicRemoteCollectionId, false) + await deployIncremental(privateRemoteCollectionId, localCollection, publicRemoteCollectionId) } const releaseAll = async () => { From 27f29e27c657e6edd25b199bec72c714790986ff Mon Sep 17 00:00:00 2001 From: barduinor Date: Thu, 21 Sep 2023 13:03:50 -0400 Subject: [PATCH 19/34] WIP: added auth api key and oauth 2 to create env and auth helper folders --- src/CollectionAdvanced.js | 59 ++++++++++++++++++++++++++++++++------- 1 file changed, 49 insertions(+), 10 deletions(-) diff --git a/src/CollectionAdvanced.js b/src/CollectionAdvanced.js index 67f58b1..a96db63 100644 --- a/src/CollectionAdvanced.js +++ b/src/CollectionAdvanced.js @@ -69,19 +69,25 @@ class CollectionAdvanced extends Collection { injectUtilities (localCollection) { // insert Utils folder at top level item + // TODO: Add proper description const folderUtilities = this.createFolder('(Utilities)', null, 'Utility scripts for Postman Collection') localCollection.item.unshift(folderUtilities) // insert create environment into Utils folder + // TODO: Add proper description const folderCreateEnvironments = this.createFolder('Create Environments', folderUtilities.id, 'Utility scripts for Postman Collection') + folderCreateEnvironments.auth = this.authAPIKey() localCollection.item.splice(1, 0, folderCreateEnvironments) // insert test environment into Utils folder + // TODO: Add proper description const folderTestEnvironments = this.createFolder('Test Environments', folderUtilities.id, 'Utility scripts for Postman Collection') localCollection.item.splice(2, 0, folderTestEnvironments) - // insert Authorixe OAuth Box App Helper into Utils folder + // insert Authorize OAuth Box App Helper into Utils folder + // TODO: Add proper description const folderAuthorizeOAuthBoxAppHelper = this.createFolder('Authorize OAuth Box App Helper', folderUtilities.id, 'Utility scripts for Postman Collection') + folderAuthorizeOAuthBoxAppHelper.auth = this.authOAuth2AutoRefresh() localCollection.item.splice(3, 0, folderAuthorizeOAuthBoxAppHelper) return localCollection @@ -111,24 +117,57 @@ class CollectionAdvanced extends Collection { } } - authOAuth () { + authAPIKey () { + return { + type: 'apikey', + apikey: [ + { + key: 'value', + value: null + }, + { + key: 'key', + value: 'X-API-Key' + } + ] + } + } + + authOAuth2AutoRefresh () { return { type: 'oauth2', oauth2: [ { - key: 'accessToken', - value: '{{access_token}}', - type: 'string' + key: 'clientSecret', + value: '{{client_secret}}' }, { - key: 'tokenType', - value: 'bearer', - type: 'string' + key: 'clientId', + value: '{{client_id}}' + }, + { + key: 'tokenName', + value: 'Box OAuth Token' + }, + { + key: 'accessTokenUrl', + value: 'https://{{api.box.com}}/oauth2/token' + }, + { + key: 'authUrl', + value: 'https://{{account.box.com}}/api/oauth2/authorize' + }, + { + key: 'client_authentication', + value: 'body' + }, + { + key: 'useBrowser', + value: true }, { key: 'addTokenTo', - value: 'header', - type: 'string' + value: 'header' } ] } From 53b2ffc21e5b9b13149e254f7f3099cbc6d61aca Mon Sep 17 00:00:00 2001 From: barduinor Date: Thu, 21 Sep 2023 14:26:52 -0400 Subject: [PATCH 20/34] WIP: added get workspace method --- src/CollectionAdvanced.js | 29 +++++++++++++++++++++++++++++ src/DeployIncremental.js | 18 ++++++++++++++++-- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/src/CollectionAdvanced.js b/src/CollectionAdvanced.js index a96db63..a291834 100644 --- a/src/CollectionAdvanced.js +++ b/src/CollectionAdvanced.js @@ -77,6 +77,7 @@ class CollectionAdvanced extends Collection { // TODO: Add proper description const folderCreateEnvironments = this.createFolder('Create Environments', folderUtilities.id, 'Utility scripts for Postman Collection') folderCreateEnvironments.auth = this.authAPIKey() + folderCreateEnvironments.item.push(this.endPointGetWorkspaces(folderCreateEnvironments.id)) localCollection.item.splice(1, 0, folderCreateEnvironments) // insert test environment into Utils folder @@ -197,6 +198,34 @@ class CollectionAdvanced extends Collection { script.script.id = Utils.GenID(hash) // RB: to big for uuidv5 return script } + + // utilities end points from JSON file + + endPointGetWorkspaces (folderParentId) { + const endPoint = { + folder: folderParentId, + name: 'Get Workspaces', + description: "Gets all [workspaces](https://learning.postman.com/docs/collaborating-in-postman/using-workspaces/creating-workspaces/). The response includes your workspaces and any workspaces that you have access to.\n\n**Note:**\n\nThis endpoint's response contains the `visibility` field. [Visibility](https://learning.postman.com/docs/collaborating-in-postman/using-workspaces/managing-workspaces/#changing-workspace-visibility) determines who can access the workspace:\n\n- `personal` — Only you can access the workspace.\n- `team` — All team members can access the workspace.\n- `private` — Only invited team members can access the workspace ([Professional and Enterprise plans only](https://www.postman.com/pricing)).\n- `public` — Everyone can access the workspace.\n- `partner` — Only invited team members and [partners](https://learning.postman.com/docs/collaborating-in-postman/using-workspaces/partner-workspaces/) can access the workspace ([Enterprise Ultimate plans](https://www.postman.com/pricing) only).", + method: 'GET', + url: 'https://api.getpostman.com/workspaces', + queryParams: [ + { + key: 'type', + value: '', + description: 'The type of workspace to filter the response by:\n\n* `personal`\n* `team`\n* `private`\n* `public`\n* `partner`', + enabled: false + }, + { + key: 'include', + value: '', + description: "Include the following information in the endpoint's response:\n- `mocks:deactivated` — Include all deactivated mock servers in the response.", + enabled: false + } + ] + } + endPoint.id = Utils.GenID(JSON.stringify(endPoint)) + return endPoint + } } module.exports = CollectionAdvanced diff --git a/src/DeployIncremental.js b/src/DeployIncremental.js index f44b2b4..0f6192b 100644 --- a/src/DeployIncremental.js +++ b/src/DeployIncremental.js @@ -114,6 +114,7 @@ const checkFolderSortChanges = (remoteCollection, localCollection) => { const remoteFolders = remoteCollection.collection.item .map(folder => ({ id: folder.id })) const localFolders = localCollection.item + .filter(folder => !folder.folder) .map(folder => ({ id: folder.id })) const remoteFoldersHash = GenID(JSON.stringify(remoteFolders)) @@ -200,6 +201,8 @@ async function mergeFolders (remoteCollection, localCollection) { const localFolders = localCollection.item const newFolders = localFolders.filter(localFolder => !remoteFolders.find(remoteFolder => remoteFolder.id === localFolder.id)) + + // TODO: RB: need a method to return all remot folders independent where they are in the collection const oldFolders = remoteFolders.filter(remoteFolder => !localFolders.find(localFolder => localFolder.id === remoteFolder.id)) let hasChanges = newFolders.length > 0 || oldFolders.length > 0 @@ -273,13 +276,18 @@ async function mergeRequests (remoteCollection, localCollection) { // // need to handle the case where the folder is empty // in that case the item property is undefined - const remoteRemoteFolder = remoteFoldersRequest.find(remoteFolder => ((remoteFolder.id === localFolder.id))) + let remoteRemoteFolder = remoteFoldersRequest.find(remoteFolder => ((remoteFolder.id === localFolder.id))) // subfolders exist in the local collection as root folders // but in the remote collection they are in the parent folder // so we need to handle the case where the subfolder // exists as a root element in the local collection // but not in the remote collection + if (!remoteRemoteFolder) { + // try locating inside the first level items + remoteRemoteFolder = remoteFoldersRequest.find(remoteFolder => ((remoteFolder.item.id === localFolder.item.id))) + } + if (!remoteRemoteFolder) { continue } @@ -308,7 +316,13 @@ async function mergeRequests (remoteCollection, localCollection) { // create new requests for (const request of newRequests) { - const pmRequest = pmConvert.requestFromLocal(request) + // check request format and convert if necessary + let pmRequest = null + if (!request.request) { // => Postman Format + pmRequest = request + } else { // => OpenAPI Format + pmRequest = pmConvert.requestFromLocal(request) + } const msg = ` Creating new request [${request.name}]` await new pmAPI.Request(remoteCollection.collection.info.uid) From fc6a9b850dbb1c2323b560f23767091b6581c4dd Mon Sep 17 00:00:00 2001 From: barduinor Date: Thu, 21 Sep 2023 16:18:07 -0400 Subject: [PATCH 21/34] WIP: refactor search for folders, requests and responses --- src/DeployIncremental.js | 89 ++++++++++++++++------------------------ 1 file changed, 35 insertions(+), 54 deletions(-) diff --git a/src/DeployIncremental.js b/src/DeployIncremental.js index 0f6192b..f95753c 100644 --- a/src/DeployIncremental.js +++ b/src/DeployIncremental.js @@ -196,13 +196,11 @@ const checkVariableChanges = (remoteCollection, localCollection) => { async function mergeFolders (remoteCollection, localCollection) { console.log(' Deploying Folders:') - const remoteFolders = remoteCollection.collection.item - .map(folder => ({ id: folder.id, name: folder.name })) - const localFolders = localCollection.item - const newFolders = localFolders.filter(localFolder => !remoteFolders.find(remoteFolder => remoteFolder.id === localFolder.id)) + const remoteFolders = getAllFoldersFromCollectionItem(remoteCollection.collection.item) + const localFolders = localCollection.item // all folders - // TODO: RB: need a method to return all remot folders independent where they are in the collection + const newFolders = localFolders.filter(localFolder => !remoteFolders.find(remoteFolder => remoteFolder.id === localFolder.id)) const oldFolders = remoteFolders.filter(remoteFolder => !localFolders.find(localFolder => localFolder.id === remoteFolder.id)) let hasChanges = newFolders.length > 0 || oldFolders.length > 0 @@ -260,46 +258,24 @@ async function mergeFolders (remoteCollection, localCollection) { } async function mergeRequests (remoteCollection, localCollection) { - const remoteFoldersRequest = remoteCollection.collection.item - .map(folder => ({ id: folder.id, name: folder.name, item: folder.item })) - const localFoldersRequest = localCollection.item - .map(folder => ({ id: folder.id, name: folder.name, item: folder.item })) + const remoteFolders = getAllFoldersFromCollectionItem(remoteCollection.collection.item) + const localFolders = localCollection.item // all folders console.log('\n Deploying Requests:') let anyRequestHasChanged = false // loop folders - for (const localFolder of localFoldersRequest) { - // original code - // const remoteRequests = remoteFoldersRequest.find(remoteFolder => remoteFolder.id === localFolder.id).item - // const localRequests = localFolder.item - // - // need to handle the case where the folder is empty - // in that case the item property is undefined - let remoteRemoteFolder = remoteFoldersRequest.find(remoteFolder => ((remoteFolder.id === localFolder.id))) - - // subfolders exist in the local collection as root folders - // but in the remote collection they are in the parent folder - // so we need to handle the case where the subfolder - // exists as a root element in the local collection - // but not in the remote collection - if (!remoteRemoteFolder) { - // try locating inside the first level items - remoteRemoteFolder = remoteFoldersRequest.find(remoteFolder => ((remoteFolder.item.id === localFolder.item.id))) - } + for (const localFolder of localFolders) { + const remoteRemoteFolder = remoteFolders.find(remoteFolder => ((remoteFolder.id === localFolder.id))) - if (!remoteRemoteFolder) { - continue - } - - // handle undifined items + // TODO: RB: get requests by folder + // handle undefined items remoteRemoteFolder.item = remoteRemoteFolder.item || [] // filter out anything that is not a request remoteRemoteFolder.item = remoteRemoteFolder.item.filter(request => request.request) const remoteRequests = remoteRemoteFolder.item - const localRequests = localFolder.item // Identify old and new requests @@ -373,44 +349,33 @@ async function mergeRequests (remoteCollection, localCollection) { async function mergeResponses (remoteCollection, localCollection) { console.log('\n Deploying Response:') - const remoteFoldersRequest = remoteCollection.collection.item - .map(folder => ({ id: folder.id, name: folder.name, item: folder.item })) - - const localFoldersRequest = localCollection.item - .map(folder => ({ id: folder.id, name: folder.name, item: folder.item })) + const remoteFolders = getAllFoldersFromCollectionItem(remoteCollection.collection.item) + const localFolders = localCollection.item let anyResponseHasChanged = false // loop folders - for (const localFolder of localFoldersRequest) { - // const remoteRequests = remoteFoldersRequest.find(remoteFolder => remoteFolder.id === localFolder.id).item - // need to handle the case where the folder is empty - // in that case the item property is undefined - const remoteRemoteFolder = remoteFoldersRequest.find(remoteFolder => ((remoteFolder.id === localFolder.id))) - - // subfolders exist in the local collection as root folders - // but in the remote collection they are in the parent folder - // so we need to handle the case where the subfolder - // exists as a root element in the local collection - // but not in the remote collection - if (!remoteRemoteFolder) { - continue - } + for (const localFolder of localFolders) { + const remoteRemoteFolder = remoteFolders.find(remoteFolder => ((remoteFolder.id === localFolder.id))) - // handle undifined items + // handle undefined items remoteRemoteFolder.item = remoteRemoteFolder.item || [] // filter out anything that is not a request remoteRemoteFolder.item = remoteRemoteFolder.item.filter(request => request.request) const remoteRequests = remoteRemoteFolder.item - const localRequests = localFolder.item console.log(' In Folder: ', localFolder.name) // loop requests for (const localRequest of localRequests) { + // Postman Request format does not have a response property const remoteResponses = remoteRequests.find(remoteRequest => remoteRequest.id === localRequest.id).response const localResponses = localRequest.response + // the request may not have responses + if (!localResponses) { + continue + } const newResponses = localResponses.filter(localResponse => !remoteResponses.find(remoteResponse => remoteResponse.id === localResponse.id)) const oldResponses = remoteResponses.filter(remoteResponse => !localResponses.find(localResponse => localResponse.id === remoteResponse.id)) @@ -484,6 +449,22 @@ async function refreshRemoteCollection (remoteCollectionID) { return remoteCollection } +// return all folders in the collection +// independently of where they are +const getAllFoldersFromCollectionItem = (collectionItem) => { + const folders = [] + const processItem = (item) => { + if (!item.request && !item.responses) { + folders.push({ id: item.id, name: item.name, item: item.item }) + } + if (item.item) { + item.item.forEach(processItem) + } + } + collectionItem.forEach(processItem) + return folders +} + // Handle axios error const handlePostmanAPIError = (error) => { if (error.response) { From 3aba445dd9d59b352e402ad6bde489a407bb8caa Mon Sep 17 00:00:00 2001 From: barduinor Date: Thu, 21 Sep 2023 16:57:41 -0400 Subject: [PATCH 22/34] added utilities requests to create and test environments --- src/CollectionAdvanced.js | 190 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 182 insertions(+), 8 deletions(-) diff --git a/src/CollectionAdvanced.js b/src/CollectionAdvanced.js index a291834..e9d8cd5 100644 --- a/src/CollectionAdvanced.js +++ b/src/CollectionAdvanced.js @@ -74,20 +74,26 @@ class CollectionAdvanced extends Collection { localCollection.item.unshift(folderUtilities) // insert create environment into Utils folder - // TODO: Add proper description - const folderCreateEnvironments = this.createFolder('Create Environments', folderUtilities.id, 'Utility scripts for Postman Collection') + let description = "These requests will help you to create an enviroment that will support the automatic token request or refresh.\n\nFor this you'll need:\n\n- A Postman API key that you can configure in your account settings\n- The ID of your workspace (you can use the \"Get Workspaces\" request to list them all)\n \n\nEach request will create the environment with the specific variables necessary for the token request or refresh.\n\nYou can fill in the required data on the request body, or alternatively, fill in the data in the environment.\n\nEither way this data will end up in your postman account.\n\nYou can create multiple environments for multiple Box Applications, and quickly switch betwene them." + const folderCreateEnvironments = this.createFolder('Create Environments', folderUtilities.id, description) folderCreateEnvironments.auth = this.authAPIKey() folderCreateEnvironments.item.push(this.endPointGetWorkspaces(folderCreateEnvironments.id)) + folderCreateEnvironments.item.push(this.endPointCreateBaererEnvironment(folderCreateEnvironments.id)) + folderCreateEnvironments.item.push(this.endPointCreateOAuthEnvironment(folderCreateEnvironments.id)) + folderCreateEnvironments.item.push(this.endPointCreateCCGEnvironment(folderCreateEnvironments.id)) + folderCreateEnvironments.item.push(this.endPointCreateJWTEnvironment(folderCreateEnvironments.id)) + localCollection.item.splice(1, 0, folderCreateEnvironments) // insert test environment into Utils folder - // TODO: Add proper description - const folderTestEnvironments = this.createFolder('Test Environments', folderUtilities.id, 'Utility scripts for Postman Collection') + description = 'Using the Box API /users/me is a good way to test if you can connect to the API.\n\nTo test the connectivity of the environment:\n\n- Select an environment\n- Execute the request\n \n\nYou should get back details on the user who is logged in.' + const folderTestEnvironments = this.createFolder('Test Environments', folderUtilities.id, description) + folderTestEnvironments.item.push(this.endPointTestEnvironment(folderTestEnvironments.id)) localCollection.item.splice(2, 0, folderTestEnvironments) // insert Authorize OAuth Box App Helper into Utils folder - // TODO: Add proper description - const folderAuthorizeOAuthBoxAppHelper = this.createFolder('Authorize OAuth Box App Helper', folderUtilities.id, 'Utility scripts for Postman Collection') + description = "I order to use OAuth 2.0, you must first authorize the application.\n\nYou also need to re-authorize the application if the refresh token has expired, which in case of Box is 60 days.\n\nTo use this you will need the following from your Box application:\n\n- Client ID\n- Cleint Secret\n- Redirect URI configured as: [https://oauth.pstmn.io/v1/callback](https://oauth.pstmn.io/v1/callback)\n \n\nTo start the process:\n\n- Select an OAuth environment that has at least the cliend and secret id's\n- Open the authorization tab in Postman, scroll all the way down and press \"Get New Access Token\"\n \n\nTo view the token retreived using this helper:\n\n- Open this Authorization tab\n- Under. Current Token, Token\n \n\nUpdate your OAuth enviroment settings with the information from this token:\n\n- Copy the access token to access token\n- Copy refresh token to refresh token\n- You can ignore the expire at\n- But you must set the refresh token expires at\n- Add 4,000,000 to the time stamp you got back\n \n\nAs you use the api, new access and refresh tokens will be fetch automatically." + const folderAuthorizeOAuthBoxAppHelper = this.createFolder('Authorize OAuth Box App Helper', folderUtilities.id, description) folderAuthorizeOAuthBoxAppHelper.auth = this.authOAuth2AutoRefresh() localCollection.item.splice(3, 0, folderAuthorizeOAuthBoxAppHelper) @@ -223,9 +229,177 @@ class CollectionAdvanced extends Collection { } ] } - endPoint.id = Utils.GenID(JSON.stringify(endPoint)) + endPoint.id = Utils.GenID(folderParentId + JSON.stringify(endPoint)) + return endPoint + } + + endPointCreateBaererEnvironment (folderParentId) { + const endPoint = { + name: 'Create Bearer Environment', + dataMode: 'raw', + rawModeData: '{\n "environment": {\n "name": "Box Bearer",\n "values": [\n {\n "type": "secret",\n "value": "",\n "key": "access_token"\n },\n {\n "type": "default",\n "value": "BEARER",\n "key": "box_env_type"\n }\n ]\n }\n}', + descriptionFormat: null, + description: "Creates an environment. Include the following properties in the request body:\n\n* `name` — A **string** that contains the environment's name.\n\nYou can also include the following properties:\n\n* `values` — An array of objects that contains the following:\n * `key` — The variable's name.\n * `value` — The variable's value.\n * `enabled` — If true, enable the variable.\n * `type` — The variable's type. One of: `secret`, `default`, or `any`.", + headers: 'Content-Type: application/json', + method: 'POST', + pathVariables: {}, + url: 'https://api.getpostman.com/environments?workspace=', + queryParams: [ + { + key: 'workspace', + value: '', + equals: true, + description: 'A workspace ID in which to create the environment.\n\nIf you do not include this query parameter, the system creates the environment in your "My Workspace" workspace.', + enabled: true + } + ], + headerData: [ + { + key: 'Content-Type', + value: 'application/json' + } + ], + pathVariableData: [], + dataDisabled: false, + dataOptions: { + raw: {} + } + } + endPoint.id = Utils.GenID(folderParentId + JSON.stringify(endPoint)) + return endPoint + } + + endPointCreateOAuthEnvironment (folderParentId) { + const endPoint = { + name: 'Create OAuth Environment', + dataMode: 'raw', + rawModeData: '{\n "environment": {\n "name": "Box OAuth",\n "values": [\n {\n "type": "default",\n "value": "",\n "key": "client_id"\n },\n {\n "type": "secret",\n "value": "",\n "key": "client_secret"\n },\n {\n "type": "secret",\n "value": "",\n "key": "access_token"\n },\n {\n "type": "default",\n "value": "0",\n "key": "expires_at"\n },\n {\n "type": "secret",\n "value": "",\n "key": "refresh_token"\n },\n {\n "type": "default",\n "value": "0",\n "key": "refresh_token_expires_at"\n },\n {\n "type": "default",\n "value": "OAUTH",\n "key": "box_env_type"\n }\n ]\n }\n}', + descriptionFormat: null, + description: "Creates an environment. Include the following properties in the request body:\n\n* `name` — A **string** that contains the environment's name.\n\nYou can also include the following properties:\n\n* `values` — An array of objects that contains the following:\n * `key` — The variable's name.\n * `value` — The variable's value.\n * `enabled` — If true, enable the variable.\n * `type` — The variable's type. One of: `secret`, `default`, or `any`.", + headers: 'Content-Type: application/json', + method: 'POST', + pathVariables: {}, + url: 'https://api.getpostman.com/environments?workspace=', + queryParams: [ + { + key: 'workspace', + value: '', + equals: true, + description: 'Optional. A workspace ID in which to create the environment.\n\nIf you do not include this query parameter, the system creates the environment in your "My Workspace" workspace.', + enabled: true + } + ], + headerData: [ + { + key: 'Content-Type', + value: 'application/json' + } + ], + pathVariableData: [], + dataDisabled: false, + dataOptions: { + raw: {} + } + } + endPoint.id = Utils.GenID(folderParentId + JSON.stringify(endPoint)) + return endPoint + } + + endPointCreateCCGEnvironment (folderParentId) { + const endPoint = { + name: 'Create CCG Environment', + dataMode: 'raw', + rawModeData: '{\n "environment": {\n "name": "Box CCG",\n "values": [\n {\n "type": "default",\n "value": "",\n "key": "client_id"\n },\n {\n "type": "secret",\n "value": "",\n "key": "client_secret"\n },\n {\n "type": "default",\n "value": "enterprise",\n "key": "box_subject_type"\n },\n {\n "type": "default",\n "value": "YOUR ENTERPRISE ID",\n "key": "box_subject_id"\n },\n {\n "type": "secret",\n "value": "",\n "key": "access_token"\n },\n {\n "type": "default",\n "value": "0",\n "key": "expires_at"\n },\n {\n "type": "default",\n "value": "CCG",\n "key": "box_env_type"\n }\n ]\n }\n}', + descriptionFormat: null, + description: "Creates an environment. Include the following properties in the request body:\n\n* `name` — A **string** that contains the environment's name.\n\nYou can also include the following properties:\n\n* `values` — An array of objects that contains the following:\n * `key` — The variable's name.\n * `value` — The variable's value.\n * `enabled` — If true, enable the variable.\n * `type` — The variable's type. One of: `secret`, `default`, or `any`.", + headers: 'Content-Type: application/json', + method: 'POST', + pathVariables: {}, + url: 'https://api.getpostman.com/environments?workspace=', + queryParams: [ + { + key: 'workspace', + value: '', + equals: true, + description: 'A workspace ID in which to create the environment.\n\nIf you do not include this query parameter, the system creates the environment in your "My Workspace" workspace.', + enabled: true + } + ], + headerData: [ + { + key: 'Content-Type', + value: 'application/json' + } + ], + pathVariableData: [], + dataDisabled: false, + dataOptions: { + raw: {} + } + } + endPoint.id = Utils.GenID(folderParentId + JSON.stringify(endPoint)) return endPoint } -} + endPointCreateJWTEnvironment (folderParentId) { + const endPoint = { + name: 'Create JWT Environment', + dataMode: 'raw', + rawModeData: '{\n "environment": {\n "name": "Box JWT",\n "values": [\n {\n "type": "default",\n "value": "",\n "key": "client_id"\n },\n {\n "type": "secret",\n "value": "",\n "key": "client_secret"\n },\n {\n "type": "default",\n "value": "enterprise",\n "key": "box_subject_type"\n },\n {\n "type": "default",\n "value": "YOUR ENTERPRISE ID",\n "key": "box_subject_id"\n },\n {\n "type": "default",\n "value": "",\n "key": "key_id"\n },\n {\n "type": "secret",\n "value": "",\n "key": "private_key_encrypted"\n },\n {\n "type": "secret",\n "value": "",\n "key": "private_key_passphrase"\n },\n {\n "type": "secret",\n "value": "",\n "key": "access_token"\n },\n {\n "type": "default",\n "value": "0",\n "key": "expires_at"\n },\n {\n "type": "default",\n "value": "JWT",\n "key": "box_env_type"\n }\n ]\n }\n}', + descriptionFormat: null, + description: "Creates an environment. Include the following properties in the request body:\n\n* `name` — A **string** that contains the environment's name.\n\nYou can also include the following properties:\n\n* `values` — An array of objects that contains the following:\n * `key` — The variable's name.\n * `value` — The variable's value.\n * `enabled` — If true, enable the variable.\n * `type` — The variable's type. One of: `secret`, `default`, or `any`.", + headers: 'Content-Type: application/json', + method: 'POST', + pathVariables: {}, + url: 'https://api.getpostman.com/environments?workspace=', + queryParams: [ + { + key: 'workspace', + equals: true, + description: 'A workspace ID in which to create the environment.\n\nIf you do not include this query parameter, the system creates the environment in your "My Workspace" workspace.', + enabled: true + } + ], + headerData: [ + { + key: 'Content-Type', + value: 'application/json' + } + ], + pathVariableData: [], + dataDisabled: false, + dataOptions: { + raw: {} + } + } + endPoint.id = Utils.GenID(folderParentId + JSON.stringify(endPoint)) + return endPoint + } + + endPointTestEnvironment (folderParentId) { + const endPoint = { + name: 'Test Environment', + descriptionFormat: null, + description: 'Retrieves information about the user who is currently authenticated.\n\nhttps://developer.box.com/reference/get-users-me', + headers: '', + method: 'GET', + pathVariables: {}, + url: 'https://{{api.box.com}}/2.0/users/me?fields=id,type,name,login', + queryParams: [ + { + key: 'fields', + description: 'A comma-separated list of attributes to include in the\nresponse. This can be used to request fields that are\nnot normally returned in a standard response.\n\nBe aware that specifying this parameter will have the\neffect that none of the standard fields are returned in\nthe response unless explicitly specified, instead only\nfields for the mini representation are returned, additional\nto the fields requested.', + enabled: true, + value: 'id,type,name,login', + equals: true + } + ], + headerData: [], + pathVariableData: [], + dataDisabled: false + } + endPoint.id = Utils.GenID(folderParentId + JSON.stringify(endPoint)) + return endPoint + } +} module.exports = CollectionAdvanced From cf1c90a02f1bbde641100b1f03d354b0705e4f48 Mon Sep 17 00:00:00 2001 From: barduinor Date: Thu, 21 Sep 2023 17:31:55 -0400 Subject: [PATCH 23/34] fix typo in request param --- src/CollectionAdvanced.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CollectionAdvanced.js b/src/CollectionAdvanced.js index e9d8cd5..4c5763e 100644 --- a/src/CollectionAdvanced.js +++ b/src/CollectionAdvanced.js @@ -285,7 +285,7 @@ class CollectionAdvanced extends Collection { key: 'workspace', value: '', equals: true, - description: 'Optional. A workspace ID in which to create the environment.\n\nIf you do not include this query parameter, the system creates the environment in your "My Workspace" workspace.', + description: 'A workspace ID in which to create the environment.\n\nIf you do not include this query parameter, the system creates the environment in your "My Workspace" workspace.', enabled: true } ], From 1df93ab1570a5873741c91821e18b424a3b8e66d Mon Sep 17 00:00:00 2001 From: barduinor Date: Wed, 27 Sep 2023 12:40:27 -0400 Subject: [PATCH 24/34] fix rsa lib not being added to the collection as a variable --- src/Collection.js | 9 +-------- src/CollectionAdvanced.js | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/src/Collection.js b/src/Collection.js index 81dde79..a50caed 100644 --- a/src/Collection.js +++ b/src/Collection.js @@ -168,14 +168,7 @@ class Collection { value: host, type: 'string' })) - // add a variable for each of the JWT JS 3rd party libraries - const libJSRSASign = { - id: Utils.GenID('libJSRSASign'), - key: 'libJSRSASign', - value: null, - type: 'string' - } - variables.push(libJSRSASign) + return variables } diff --git a/src/CollectionAdvanced.js b/src/CollectionAdvanced.js index 4c5763e..a88e75f 100644 --- a/src/CollectionAdvanced.js +++ b/src/CollectionAdvanced.js @@ -2,6 +2,7 @@ require('dotenv').config() const fs = require('fs') const Utils = require('./Utils') +const { uniq } = require('lodash') const Collection = require('./Collection') @@ -67,6 +68,25 @@ class CollectionAdvanced extends Collection { // PRIVATE + /** + * Extracts all server URLs as variables + */ + getVariables () { + const variables = uniq(Object.values(this.openapi.paths).flatMap(endpoints => ( + Object.values(endpoints).map(endpoint => this.server(endpoint).host) + ))).map(host => ({ + id: Utils.GenID(host), + key: host, // .replace(/\./g, '_'), + value: host, + type: 'string' + })) + // add a variable for each of the JWT JS 3rd party libraries + const libJSRSASign = this.variableLibJaRsaSign() + + variables.push(libJSRSASign) + return variables + } + injectUtilities (localCollection) { // insert Utils folder at top level item // TODO: Add proper description @@ -188,6 +208,19 @@ class CollectionAdvanced extends Collection { return [] } + variableLibJaRsaSign () { + const scriptString = String(fs.readFileSync('./src/events/libJsRSASign.min.js')) + const libJSRSASign = { + id: Utils.GenID('libJSRSASign'), + key: 'libJSRSASign', + value: scriptString, + type: 'string' + } + const hash = this.calculateHash(scriptString) + libJSRSASign.id = Utils.GenID(hash) // RB: to big for uuidv5 + return libJSRSASign + } + /** * Creates a pre-request event for collection */ From 5d04e99bb1c801a7f0370cbfca5023270e9a9654 Mon Sep 17 00:00:00 2001 From: barduinor Date: Wed, 27 Sep 2023 12:49:05 -0400 Subject: [PATCH 25/34] updated pr-req script to handle \n in the private key --- src/events/collectionPreReqScript.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/events/collectionPreReqScript.js b/src/events/collectionPreReqScript.js index 84fbf02..3c5f9c6 100644 --- a/src/events/collectionPreReqScript.js +++ b/src/events/collectionPreReqScript.js @@ -157,12 +157,13 @@ function get_jwt_assertion () { navigator = {} window = {} /* eslint-disable no-eval */ + eval(libJSRSASign) // UUID const uuid = require('uuid') - const private_key_encrypted = pm.environment.get('private_key_encrypted') + const private_key_encrypted = pm.environment.get('private_key_encrypted').replace(/\\n/g, '') const private_key_passphrase = pm.environment.get('private_key_passphrase') const private_key = KEYUTIL.getKey(private_key_encrypted, private_key_passphrase) @@ -178,6 +179,7 @@ function get_jwt_assertion () { const iat = KJUR.jws.IntDate.get('now') const header = { alg: 'RS512', typ: 'JWT', kid: kid } + // console.log(`header: ${JSON.stringify(header)}`) const claims = { @@ -190,11 +192,10 @@ function get_jwt_assertion () { iat: iat } - const jwt = KJUR.jws.JWS.sign(null, header, claims, private_key) + // console.log(`claim set: ${JSON.stringify(claims)}`) - // console.log(`header: ${JSON.stringify(header)}`) - // console.log(`claim set: ${JSON.stringify(claims)}`) - // console.log('JWT Assertion: ', jwt) + const jwt = KJUR.jws.JWS.sign(null, header, claims, private_key) + console.log('JWT Assertion: ', jwt) return jwt } From 87099edce1b783109516da31045c47f7400b6918 Mon Sep 17 00:00:00 2001 From: barduinor Date: Wed, 27 Sep 2023 12:52:19 -0400 Subject: [PATCH 26/34] adjusted test not to include the extra environment variable --- tests/OpenAPICollection.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/OpenAPICollection.test.js b/tests/OpenAPICollection.test.js index fe45669..b53274d 100644 --- a/tests/OpenAPICollection.test.js +++ b/tests/OpenAPICollection.test.js @@ -27,7 +27,7 @@ describe('.convert', () => { const openAPISpec = await openapi.process() const collection = new Collection(openAPISpec, locale).process() expect(collection.item).toHaveLength(52) - expect(collection.variable).toHaveLength(3 + 1) + expect(collection.variable).toHaveLength(3) expect(collection.item[0].item[0].request.url.host).toBe('{{account.box.com}}') }) From 0ed0e6030dbe8242e8088d77152f465650063b6b Mon Sep 17 00:00:00 2001 From: barduinor Date: Wed, 27 Sep 2023 12:56:52 -0400 Subject: [PATCH 27/34] adjusted pre-req script to remove an extra console.log --- src/events/collectionPreReqScript.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/events/collectionPreReqScript.js b/src/events/collectionPreReqScript.js index 3c5f9c6..6c26342 100644 --- a/src/events/collectionPreReqScript.js +++ b/src/events/collectionPreReqScript.js @@ -195,7 +195,7 @@ function get_jwt_assertion () { // console.log(`claim set: ${JSON.stringify(claims)}`) const jwt = KJUR.jws.JWS.sign(null, header, claims, private_key) - console.log('JWT Assertion: ', jwt) + // console.log('JWT Assertion: ', jwt) return jwt } From 5175033a9b3c340e122762cc57323786e0ecd1e0 Mon Sep 17 00:00:00 2001 From: barduinor Date: Wed, 27 Sep 2023 14:22:37 -0400 Subject: [PATCH 28/34] adjusted utils methods and description to be more friendly --- src/CollectionAdvanced.js | 40 +++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/src/CollectionAdvanced.js b/src/CollectionAdvanced.js index a88e75f..b868ed6 100644 --- a/src/CollectionAdvanced.js +++ b/src/CollectionAdvanced.js @@ -94,9 +94,12 @@ class CollectionAdvanced extends Collection { localCollection.item.unshift(folderUtilities) // insert create environment into Utils folder - let description = "These requests will help you to create an enviroment that will support the automatic token request or refresh.\n\nFor this you'll need:\n\n- A Postman API key that you can configure in your account settings\n- The ID of your workspace (you can use the \"Get Workspaces\" request to list them all)\n \n\nEach request will create the environment with the specific variables necessary for the token request or refresh.\n\nYou can fill in the required data on the request body, or alternatively, fill in the data in the environment.\n\nEither way this data will end up in your postman account.\n\nYou can create multiple environments for multiple Box Applications, and quickly switch betwene them." + let description = "These requests will help you to create an enviroment that will support the automatic token request or refresh.\n\nFor this you'll need:\n\n- A Postman API key that you can configure in your account settings\n- The ID of your workspace (you can use the \"Get Workspaces\" request to list them all)\n \n\nEach request will create the environment with the specific variables necessary for the token request or refresh.\n\nYou can fill in the required data on the request body, or alternatively, fill in the data in the environment.\n\nEither way this data will end up in your postman account.\n\nYou can create multiple environments for multiple Box Applications, and quickly switch betwene them.\n\n**Steps**:\n\n- Goto your account and under API keys generate a new api key\n- In Postman, under environments, global, create a varibale named personal-pm-pmak as a secret and paste the PMAK you created in the previous step. Remember to save.\n- In this collection, under the create environments, use the get workspaces to identify the current workspace, and copy its id.\n- In. Postman, under environments, global, create a variable named wokspaceid and paste the id you copied from the previous step. Remember to save.\n \n\nYou're all set." const folderCreateEnvironments = this.createFolder('Create Environments', folderUtilities.id, description) folderCreateEnvironments.auth = this.authAPIKey() + folderCreateEnvironments.id = null + folderCreateEnvironments.id = Utils.GenID(folderUtilities.id + JSON.stringify(folderCreateEnvironments)) + folderCreateEnvironments.item.push(this.endPointGetWorkspaces(folderCreateEnvironments.id)) folderCreateEnvironments.item.push(this.endPointCreateBaererEnvironment(folderCreateEnvironments.id)) folderCreateEnvironments.item.push(this.endPointCreateOAuthEnvironment(folderCreateEnvironments.id)) @@ -109,12 +112,16 @@ class CollectionAdvanced extends Collection { description = 'Using the Box API /users/me is a good way to test if you can connect to the API.\n\nTo test the connectivity of the environment:\n\n- Select an environment\n- Execute the request\n \n\nYou should get back details on the user who is logged in.' const folderTestEnvironments = this.createFolder('Test Environments', folderUtilities.id, description) folderTestEnvironments.item.push(this.endPointTestEnvironment(folderTestEnvironments.id)) + localCollection.item.splice(2, 0, folderTestEnvironments) // insert Authorize OAuth Box App Helper into Utils folder description = "I order to use OAuth 2.0, you must first authorize the application.\n\nYou also need to re-authorize the application if the refresh token has expired, which in case of Box is 60 days.\n\nTo use this you will need the following from your Box application:\n\n- Client ID\n- Cleint Secret\n- Redirect URI configured as: [https://oauth.pstmn.io/v1/callback](https://oauth.pstmn.io/v1/callback)\n \n\nTo start the process:\n\n- Select an OAuth environment that has at least the cliend and secret id's\n- Open the authorization tab in Postman, scroll all the way down and press \"Get New Access Token\"\n \n\nTo view the token retreived using this helper:\n\n- Open this Authorization tab\n- Under. Current Token, Token\n \n\nUpdate your OAuth enviroment settings with the information from this token:\n\n- Copy the access token to access token\n- Copy refresh token to refresh token\n- You can ignore the expire at\n- But you must set the refresh token expires at\n- Add 4,000,000 to the time stamp you got back\n \n\nAs you use the api, new access and refresh tokens will be fetch automatically." const folderAuthorizeOAuthBoxAppHelper = this.createFolder('Authorize OAuth Box App Helper', folderUtilities.id, description) folderAuthorizeOAuthBoxAppHelper.auth = this.authOAuth2AutoRefresh() + folderAuthorizeOAuthBoxAppHelper.id = null + folderAuthorizeOAuthBoxAppHelper.id = Utils.GenID(folderUtilities.id + JSON.stringify(folderAuthorizeOAuthBoxAppHelper)) + localCollection.item.splice(3, 0, folderAuthorizeOAuthBoxAppHelper) return localCollection @@ -150,7 +157,7 @@ class CollectionAdvanced extends Collection { apikey: [ { key: 'value', - value: null + value: '{{personal-pm-pmak}}' }, { key: 'key', @@ -268,7 +275,7 @@ class CollectionAdvanced extends Collection { endPointCreateBaererEnvironment (folderParentId) { const endPoint = { - name: 'Create Bearer Environment', + name: 'Create Bearer Token Environment', dataMode: 'raw', rawModeData: '{\n "environment": {\n "name": "Box Bearer",\n "values": [\n {\n "type": "secret",\n "value": "",\n "key": "access_token"\n },\n {\n "type": "default",\n "value": "BEARER",\n "key": "box_env_type"\n }\n ]\n }\n}', descriptionFormat: null, @@ -276,11 +283,11 @@ class CollectionAdvanced extends Collection { headers: 'Content-Type: application/json', method: 'POST', pathVariables: {}, - url: 'https://api.getpostman.com/environments?workspace=', + url: 'https://api.getpostman.com/environments?workspace={{wokspaceid}}', queryParams: [ { key: 'workspace', - value: '', + value: '{{wokspaceid}}', equals: true, description: 'A workspace ID in which to create the environment.\n\nIf you do not include this query parameter, the system creates the environment in your "My Workspace" workspace.', enabled: true @@ -306,17 +313,17 @@ class CollectionAdvanced extends Collection { const endPoint = { name: 'Create OAuth Environment', dataMode: 'raw', - rawModeData: '{\n "environment": {\n "name": "Box OAuth",\n "values": [\n {\n "type": "default",\n "value": "",\n "key": "client_id"\n },\n {\n "type": "secret",\n "value": "",\n "key": "client_secret"\n },\n {\n "type": "secret",\n "value": "",\n "key": "access_token"\n },\n {\n "type": "default",\n "value": "0",\n "key": "expires_at"\n },\n {\n "type": "secret",\n "value": "",\n "key": "refresh_token"\n },\n {\n "type": "default",\n "value": "0",\n "key": "refresh_token_expires_at"\n },\n {\n "type": "default",\n "value": "OAUTH",\n "key": "box_env_type"\n }\n ]\n }\n}', + rawModeData: '{\n "environment": {\n "name": "Box OAuth",\n "values": [\n {\n "type": "default",\n "value": "YOU CLIENT ID GOES HERE",\n "key": "client_id"\n },\n {\n "type": "secret",\n "value": "",\n "key": "client_secret"\n },\n {\n "type": "secret",\n "value": "",\n "key": "access_token"\n },\n {\n "type": "default",\n "value": "0",\n "key": "expires_at"\n },\n {\n "type": "secret",\n "value": "",\n "key": "refresh_token"\n },\n {\n "type": "default",\n "value": "0",\n "key": "refresh_token_expires_at"\n },\n {\n "type": "default",\n "value": "OAUTH",\n "key": "box_env_type"\n }\n ]\n }\n}', descriptionFormat: null, description: "Creates an environment. Include the following properties in the request body:\n\n* `name` — A **string** that contains the environment's name.\n\nYou can also include the following properties:\n\n* `values` — An array of objects that contains the following:\n * `key` — The variable's name.\n * `value` — The variable's value.\n * `enabled` — If true, enable the variable.\n * `type` — The variable's type. One of: `secret`, `default`, or `any`.", headers: 'Content-Type: application/json', method: 'POST', pathVariables: {}, - url: 'https://api.getpostman.com/environments?workspace=', + url: 'https://api.getpostman.com/environments?workspace={{wokspaceid}}', queryParams: [ { key: 'workspace', - value: '', + value: '{{wokspaceid}}', equals: true, description: 'A workspace ID in which to create the environment.\n\nIf you do not include this query parameter, the system creates the environment in your "My Workspace" workspace.', enabled: true @@ -342,7 +349,7 @@ class CollectionAdvanced extends Collection { const endPoint = { name: 'Create CCG Environment', dataMode: 'raw', - rawModeData: '{\n "environment": {\n "name": "Box CCG",\n "values": [\n {\n "type": "default",\n "value": "",\n "key": "client_id"\n },\n {\n "type": "secret",\n "value": "",\n "key": "client_secret"\n },\n {\n "type": "default",\n "value": "enterprise",\n "key": "box_subject_type"\n },\n {\n "type": "default",\n "value": "YOUR ENTERPRISE ID",\n "key": "box_subject_id"\n },\n {\n "type": "secret",\n "value": "",\n "key": "access_token"\n },\n {\n "type": "default",\n "value": "0",\n "key": "expires_at"\n },\n {\n "type": "default",\n "value": "CCG",\n "key": "box_env_type"\n }\n ]\n }\n}', + rawModeData: '{\n "environment": {\n "name": "Box CCG",\n "values": [\n {\n "type": "default",\n "value": "YOU CLIENT ID GOES HERE",\n "key": "client_id"\n },\n {\n "type": "secret",\n "value": "",\n "key": "client_secret"\n },\n {\n "type": "default",\n "value": "enterprise",\n "key": "box_subject_type"\n },\n {\n "type": "default",\n "value": "YOUR ENTERPRISE ID",\n "key": "box_subject_id"\n },\n {\n "type": "secret",\n "value": "",\n "key": "access_token"\n },\n {\n "type": "default",\n "value": "0",\n "key": "expires_at"\n },\n {\n "type": "default",\n "value": "CCG",\n "key": "box_env_type"\n }\n ]\n }\n}', descriptionFormat: null, description: "Creates an environment. Include the following properties in the request body:\n\n* `name` — A **string** that contains the environment's name.\n\nYou can also include the following properties:\n\n* `values` — An array of objects that contains the following:\n * `key` — The variable's name.\n * `value` — The variable's value.\n * `enabled` — If true, enable the variable.\n * `type` — The variable's type. One of: `secret`, `default`, or `any`.", headers: 'Content-Type: application/json', @@ -352,7 +359,7 @@ class CollectionAdvanced extends Collection { queryParams: [ { key: 'workspace', - value: '', + value: '{{wokspaceid}}', equals: true, description: 'A workspace ID in which to create the environment.\n\nIf you do not include this query parameter, the system creates the environment in your "My Workspace" workspace.', enabled: true @@ -378,7 +385,7 @@ class CollectionAdvanced extends Collection { const endPoint = { name: 'Create JWT Environment', dataMode: 'raw', - rawModeData: '{\n "environment": {\n "name": "Box JWT",\n "values": [\n {\n "type": "default",\n "value": "",\n "key": "client_id"\n },\n {\n "type": "secret",\n "value": "",\n "key": "client_secret"\n },\n {\n "type": "default",\n "value": "enterprise",\n "key": "box_subject_type"\n },\n {\n "type": "default",\n "value": "YOUR ENTERPRISE ID",\n "key": "box_subject_id"\n },\n {\n "type": "default",\n "value": "",\n "key": "key_id"\n },\n {\n "type": "secret",\n "value": "",\n "key": "private_key_encrypted"\n },\n {\n "type": "secret",\n "value": "",\n "key": "private_key_passphrase"\n },\n {\n "type": "secret",\n "value": "",\n "key": "access_token"\n },\n {\n "type": "default",\n "value": "0",\n "key": "expires_at"\n },\n {\n "type": "default",\n "value": "JWT",\n "key": "box_env_type"\n }\n ]\n }\n}', + rawModeData: '{\n "environment": {\n "name": "Box JWT",\n "values": [\n {\n "type": "default",\n "value": "YOU CLIENT ID GOES HERE",\n "key": "client_id"\n },\n {\n "type": "secret",\n "value": "",\n "key": "client_secret"\n },\n {\n "type": "default",\n "value": "enterprise",\n "key": "box_subject_type"\n },\n {\n "type": "default",\n "value": "YOUR ENTERPRISE ID",\n "key": "box_subject_id"\n },\n {\n "type": "default",\n "value": "YOU KEY ID GOES HERE",\n "key": "key_id"\n },\n {\n "type": "secret",\n "value": "",\n "key": "private_key_encrypted"\n },\n {\n "type": "secret",\n "value": "",\n "key": "private_key_passphrase"\n },\n {\n "type": "secret",\n "value": "",\n "key": "access_token"\n },\n {\n "type": "default",\n "value": "0",\n "key": "expires_at"\n },\n {\n "type": "default",\n "value": "JWT",\n "key": "box_env_type"\n }\n ]\n }\n}', descriptionFormat: null, description: "Creates an environment. Include the following properties in the request body:\n\n* `name` — A **string** that contains the environment's name.\n\nYou can also include the following properties:\n\n* `values` — An array of objects that contains the following:\n * `key` — The variable's name.\n * `value` — The variable's value.\n * `enabled` — If true, enable the variable.\n * `type` — The variable's type. One of: `secret`, `default`, or `any`.", headers: 'Content-Type: application/json', @@ -388,6 +395,7 @@ class CollectionAdvanced extends Collection { queryParams: [ { key: 'workspace', + value: '{{wokspaceid}}', equals: true, description: 'A workspace ID in which to create the environment.\n\nIf you do not include this query parameter, the system creates the environment in your "My Workspace" workspace.', enabled: true @@ -420,11 +428,11 @@ class CollectionAdvanced extends Collection { url: 'https://{{api.box.com}}/2.0/users/me?fields=id,type,name,login', queryParams: [ { - key: 'fields', - description: 'A comma-separated list of attributes to include in the\nresponse. This can be used to request fields that are\nnot normally returned in a standard response.\n\nBe aware that specifying this parameter will have the\neffect that none of the standard fields are returned in\nthe response unless explicitly specified, instead only\nfields for the mini representation are returned, additional\nto the fields requested.', - enabled: true, - value: 'id,type,name,login', - equals: true + key: 'workspace', + value: '{{wokspaceid}}', + equals: true, + description: 'A workspace ID in which to create the environment.\n\nIf you do not include this query parameter, the system creates the environment in your "My Workspace" workspace.', + enabled: true } ], headerData: [], From 42987a7b153fafa9dbcf7a4e2ce526b005304e83 Mon Sep 17 00:00:00 2001 From: barduinor Date: Wed, 27 Sep 2023 16:23:30 -0400 Subject: [PATCH 29/34] added the advanced collection to the read me --- README.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index a25473c..154b832 100644 --- a/README.md +++ b/README.md @@ -8,19 +8,20 @@ ## The Collections -### Auto-generated Collection +### Classic Collection A updated, up-to-date Postman Collection is created every few weeks based on the official Box [OpenAPI 3.0 Specification][openapi]. [![Run in Postman](https://run.pstmn.io/button.svg)][english] -### Japanese Collection. - -Additionally a collection is available in Japanese. +### Classic Japanese Collection. [![Run in Postman (Japanese)](https://run.pstmn.io/button.svg)][japanese] +### Advanced Collection +[![Run in Postman Advanced](https://run.pstmn.io/button.svg)][advanced] + ## Development & Contribution Please follow the [contribution guidelines](./CONTRIBUTING.md) when contributing @@ -48,5 +49,6 @@ specific language governing permissions and limitations under the License. [legacy]: https://app.getpostman.com/run-collection/768279fde466dffc5511 [openapi]: https://github.com/box/box-openapi [english]: https://god.gw.postman.com/run-collection/8119550-b5ea2aeb-c82a-425d-baff-ed5dfd1d7659?action=collection%2Ffork&collection-url=entityId%3D8119550-b5ea2aeb-c82a-425d-baff-ed5dfd1d7659%26entityType%3Dcollection%26workspaceId%3D1a5945ff-a292-42c7-91c5-2cf3cdc68492 +[advanced]: https://god.gw.postman.com/run-collection/8119550-373aba62-5af5-459b-b9a4-e9db77f947a5?action=collection%2Ffork&collection-url=entityId%3D8119550-373aba62-5af5-459b-b9a4-e9db77f947a5%26entityType%3Dcollection%26workspaceId%3D1a5945ff-a292-42c7-91c5-2cf3cdc68492 [japanese]: https://app.getpostman.com/run-collection/71097146282762048e55 [v8]: https://learning.postman.com/docs/administration/upgrading/#downloading-postman-v8 From 2cb3ce1086d78ebfca370adc93ec66607fa6167c Mon Sep 17 00:00:00 2001 From: barduinor Date: Wed, 27 Sep 2023 16:52:18 -0400 Subject: [PATCH 30/34] fixed missing params in url in create JWT and CCG environment --- src/CollectionAdvanced.js | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/src/CollectionAdvanced.js b/src/CollectionAdvanced.js index b868ed6..05571e7 100644 --- a/src/CollectionAdvanced.js +++ b/src/CollectionAdvanced.js @@ -355,7 +355,7 @@ class CollectionAdvanced extends Collection { headers: 'Content-Type: application/json', method: 'POST', pathVariables: {}, - url: 'https://api.getpostman.com/environments?workspace=', + url: 'https://api.getpostman.com/environments?workspace={{wokspaceid}}', queryParams: [ { key: 'workspace', @@ -391,7 +391,7 @@ class CollectionAdvanced extends Collection { headers: 'Content-Type: application/json', method: 'POST', pathVariables: {}, - url: 'https://api.getpostman.com/environments?workspace=', + url: 'https://api.getpostman.com/environments?workspace={{wokspaceid}}', queryParams: [ { key: 'workspace', @@ -426,15 +426,7 @@ class CollectionAdvanced extends Collection { method: 'GET', pathVariables: {}, url: 'https://{{api.box.com}}/2.0/users/me?fields=id,type,name,login', - queryParams: [ - { - key: 'workspace', - value: '{{wokspaceid}}', - equals: true, - description: 'A workspace ID in which to create the environment.\n\nIf you do not include this query parameter, the system creates the environment in your "My Workspace" workspace.', - enabled: true - } - ], + queryParams: [], headerData: [], pathVariableData: [], dataDisabled: false From afba2d333b9c2dc9848b6ca489c48fb6abcd2ff6 Mon Sep 17 00:00:00 2001 From: barduinor Date: Thu, 5 Oct 2023 12:56:20 -0400 Subject: [PATCH 31/34] fixed colision in object id + empty remote collection handling --- .DS_Store | Bin 6148 -> 0 bytes src/Collection.js | 19 +++++++++++++------ src/CollectionAdvanced.js | 17 ++++++++++++----- src/DeployIncremental.js | 15 +++++++++++++-- 4 files changed, 38 insertions(+), 13 deletions(-) delete mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 5dd6a0d4c51fd025c9bc0a02bb6771dd2c251f27..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHKyG{c!5S)b+C()#&^e^xSRusN~A3)@SgcNj0i2f?RE1$;fqaZrcg(jMn)?=@C zY@mKMpSwl&-vQ?i*kQsuK7R9G zrs?3DGASShq<|EV0#e|j3RHO=?k;+&4wC{>;2IS0??aKhr(uNO$8rC>)|36Qdk+;pO-~ ck}|LPocq0SP7FHZK_}{Gz;%&Hf&W(E2iZ0iZU6uP diff --git a/src/Collection.js b/src/Collection.js index a50caed..f3d6e94 100644 --- a/src/Collection.js +++ b/src/Collection.js @@ -110,12 +110,17 @@ class Collection { */ process () { console.log('Processing collection') + const info = this.getInfo() + this.collectionId = info._postman_id + const item = this.getItems() + const variable = this.getVariables() + const auth = this.defaultAuth() const collection = { - info: this.getInfo(), - item: this.getItems(), + info: info, + item: item, event: [], - variable: this.getVariables(), - auth: this.defaultAuth() + variable: variable, + auth: auth } console.log('Done') return collection @@ -206,7 +211,7 @@ class Collection { item: [] } - const folderId = Utils.GenID(JSON.stringify(folder)) + const folderId = Utils.GenID(this.collectionId + JSON.stringify(folder)) folder.id = folderId if (this.verbose) { console.log(` Adding Folder [${folder.name}]`) @@ -234,7 +239,9 @@ class Collection { event: this.getItemEvents(endpoint) } - const itemId = Utils.GenID(JSON.stringify(item)) + // RB: This should pickup a different object id + // unexpected object id collision + const itemId = Utils.GenID(this.collectionId + JSON.stringify(item)) item.id = itemId item.request = this.requestCreate(verb, path, endpoint, item.id) item.response = this.responseCreate(endpoint, item.request.id) diff --git a/src/CollectionAdvanced.js b/src/CollectionAdvanced.js index 05571e7..4f21f9e 100644 --- a/src/CollectionAdvanced.js +++ b/src/CollectionAdvanced.js @@ -52,12 +52,19 @@ class CollectionAdvanced extends Collection { */ // RB: override process () { + console.log('Processing collection') + const info = this.getInfo() + this.collectionId = info._postman_id + const item = this.getItems() + const event = [this.collectionPreRequest()] + const variable = this.getVariables() + const auth = this.defaultAuth() const localCollection = { - info: this.getInfo(), - item: this.getItems(), - event: [this.collectionPreRequest()], - variable: this.getVariables(), - auth: this.defaultAuth() + info, + item, + event, + variable, + auth } // RB: inject utilities diff --git a/src/DeployIncremental.js b/src/DeployIncremental.js index f95753c..521af71 100644 --- a/src/DeployIncremental.js +++ b/src/DeployIncremental.js @@ -156,8 +156,19 @@ const checkObjectChanges = (remoteCollectionObject, localCollectionObject) => { } const checkScriptChanges = (scriptType, remoteCollection, localCollection) => { - const remoteScript = remoteCollection.collection.event.find(event => event.listen === scriptType) - const localScript = localCollection.event.find(event => event.listen === scriptType) + // RB 2020-10-20: The collection may be empty or have no events at all + let remoteScript = null + let localScript = null + if (remoteCollection.collection.event) { + remoteScript = remoteCollection.collection.event.find(event => event.listen === scriptType) + } + + if (localCollection.event) { + localScript = localCollection.event.find(event => event.listen === scriptType) + } + + // const remoteScript = remoteCollection.collection.event.find(event => event.listen === scriptType) + // const localScript = localCollection.event.find(event => event.listen === scriptType) if (!remoteScript && !localScript) { return false From 188ec03b1d21ae3e98385eb325d2ec84b6425bfb Mon Sep 17 00:00:00 2001 From: barduinor Date: Wed, 11 Oct 2023 15:23:45 -0400 Subject: [PATCH 32/34] activating JP advanced collection deployment --- .github/workflows/deployAdvanced.yml | 51 +++++++++++++++++++++++++--- 1 file changed, 47 insertions(+), 4 deletions(-) diff --git a/.github/workflows/deployAdvanced.yml b/.github/workflows/deployAdvanced.yml index d1bc64a..a305cb9 100644 --- a/.github/workflows/deployAdvanced.yml +++ b/.github/workflows/deployAdvanced.yml @@ -13,17 +13,16 @@ on: jobs: # Deploys the Advanced version - deploy-adv: + deploy-adv-en: runs-on: ubuntu-latest timeout-minutes: 20 - # needs: deploy-jp env: LOCALES: "en" EN_OAS3_REPO: "https://github.com/box/box-openapi.git#en" PRIVATE_EN_POSTMAN_COLLECTION_ADVANCED_ID: "8119550-1ca6cb64-7560-4f24-a2b5-89ba095b1c17" PUBLIC_EN_POSTMAN_COLLECTION_ADVANCED_ID: "8119550-373aba62-5af5-459b-b9a4-e9db77f947a5" - CONVERT_LOG: true + # CONVERT_LOG: true POSTMAN_API_KEY: ${{ secrets.POSTMAN_API_KEY }} strategy: @@ -54,4 +53,48 @@ jobs: SLACK_USERNAME: GitHub Actions SLACK_AVATAR: "https://avatars3.githubusercontent.com/u/8659759?s=200&v=4" with: - args: "Deployed Advanced Postman collection :rocket:" \ No newline at end of file + args: "Deployed Advanced Postman English collection :rocket:" + + # Deploys the japanese version + deploy-adv-jp: + runs-on: ubuntu-latest + timeout-minutes: 20 + needs: deploy-adv-en + + env: + LOCALES: "jp" + JP_OAS3_REPO: "https://github.com/box/box-openapi.git#jp" + PRIVATE_JP_POSTMAN_COLLECTION_ADVANCED_ID: "8119550-45cd808e-0844-4e46-ada0-5d0cb4b602d2" + PUBLIC_JP_POSTMAN_COLLECTION_ADVANCED_ID: "8119550-9899c10b-11bb-4f53-9938-fced213a14d0" + # CONVERT_LOG: true + POSTMAN_API_KEY: ${{ secrets.POSTMAN_API_KEY }} + + strategy: + matrix: + node-version: [18.x] + + steps: + - name: Check out the repo + uses: actions/checkout@v3 + + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + + - name: Deploy the collection + run: | + yarn install + yarn clean + yarn pull + yarn convertAdvanced jp + yarn releaseAdvanced jp + + - name: Send Slack notification + uses: Ilshidur/action-slack@2.0.2 + env: + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} + SLACK_USERNAME: GitHub Actions + SLACK_AVATAR: "https://avatars3.githubusercontent.com/u/8659759?s=200&v=4" + with: + args: "Deployed Advanced Postman Japanese collection :rocket:" \ No newline at end of file From 3c681a1f507aa98a735b3d28f66d826116090d85 Mon Sep 17 00:00:00 2001 From: barduinor Date: Wed, 11 Oct 2023 15:32:29 -0400 Subject: [PATCH 33/34] updating readme and env sample --- .env.example | 8 ++++---- README.md | 9 +++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/.env.example b/.env.example index 5e49c03..0968093 100644 --- a/.env.example +++ b/.env.example @@ -23,8 +23,8 @@ POSTMAN_API_KEY="" # On the Box CI/CD workspace PRIVATE_EN_POSTMAN_COLLECTION_ID="8119550-3e45693c-a4d7-4d77-b02c-f7035a152898" PRIVATE_JP_POSTMAN_COLLECTION_ID="8119550-8ab5448e-636f-44ee-ba16-97908b5bc7eb" -PRIVATE_EN_POSTMAN_COLLECTION_ADVANCED_ID = "" -PRIVATE_JP_POSTMAN_COLLECTION_ADVANCED_ID = "" +PRIVATE_EN_POSTMAN_COLLECTION_ADVANCED_ID = "8119550-1ca6cb64-7560-4f24-a2b5-89ba095b1c17" +PRIVATE_JP_POSTMAN_COLLECTION_ADVANCED_ID = "8119550-45cd808e-0844-4e46-ada0-5d0cb4b602d2" # PUBLIC collection id's # These are the public collections @@ -32,5 +32,5 @@ PRIVATE_JP_POSTMAN_COLLECTION_ADVANCED_ID = "" # via merge from the private collections PUBLIC_EN_POSTMAN_COLLECTION_ID="8119550-b5ea2aeb-c82a-425d-baff-ed5dfd1d7659" PUBLIC_JP_POSTMAN_COLLECTION_ID="8119550-73df4d75-420a-455b-97c2-d3d33103c1a4" -PUBLIC_EN_POSTMAN_COLLECTION_ADVANCED_ID = "" -PUBLIC_JP_POSTMAN_COLLECTION_ADVANCED_ID = "" +PUBLIC_EN_POSTMAN_COLLECTION_ADVANCED_ID = "8119550-373aba62-5af5-459b-b9a4-e9db77f947a5" +PUBLIC_JP_POSTMAN_COLLECTION_ADVANCED_ID = "8119550-9899c10b-11bb-4f53-9938-fced213a14d0" diff --git a/README.md b/README.md index 154b832..b413c51 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,9 @@ the official Box [OpenAPI 3.0 Specification][openapi]. ### Advanced Collection [![Run in Postman Advanced](https://run.pstmn.io/button.svg)][advanced] +### Advanced Collection in Japanese +[![Run in Postman Advanced](https://run.pstmn.io/button.svg)][advanced-jp] + ## Development & Contribution Please follow the [contribution guidelines](./CONTRIBUTING.md) when contributing @@ -47,8 +50,14 @@ CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. [legacy]: https://app.getpostman.com/run-collection/768279fde466dffc5511 + [openapi]: https://github.com/box/box-openapi + [english]: https://god.gw.postman.com/run-collection/8119550-b5ea2aeb-c82a-425d-baff-ed5dfd1d7659?action=collection%2Ffork&collection-url=entityId%3D8119550-b5ea2aeb-c82a-425d-baff-ed5dfd1d7659%26entityType%3Dcollection%26workspaceId%3D1a5945ff-a292-42c7-91c5-2cf3cdc68492 + [advanced]: https://god.gw.postman.com/run-collection/8119550-373aba62-5af5-459b-b9a4-e9db77f947a5?action=collection%2Ffork&collection-url=entityId%3D8119550-373aba62-5af5-459b-b9a4-e9db77f947a5%26entityType%3Dcollection%26workspaceId%3D1a5945ff-a292-42c7-91c5-2cf3cdc68492 + +[advanced-jp]: https://god.gw.postman.com/run-collection/8119550-9899c10b-11bb-4f53-9938-fced213a14d0?action=collection%2Ffork&collection-url=entityId%3D8119550-9899c10b-11bb-4f53-9938-fced213a14d0%26entityType%3Dcollection%26workspaceId%3D1a5945ff-a292-42c7-91c5-2cf3cdc68492 + [japanese]: https://app.getpostman.com/run-collection/71097146282762048e55 [v8]: https://learning.postman.com/docs/administration/upgrading/#downloading-postman-v8 From 8a30b4e8b220a2f778a178ff2ed91378a4029838 Mon Sep 17 00:00:00 2001 From: barduinor Date: Mon, 16 Oct 2023 13:04:33 -0400 Subject: [PATCH 34/34] potman api, increase timeout from 10 to 60 seconds --- src/postmanAPI.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/postmanAPI.js b/src/postmanAPI.js index b6e7dea..92fddcf 100644 --- a/src/postmanAPI.js +++ b/src/postmanAPI.js @@ -6,7 +6,7 @@ class Collection { this.collectionId = collectionId this.apiKey = process.env.POSTMAN_API_KEY this.axios = axios.create({ - timeout: 10000, + timeout: 1000 * 60, // 60 seconds headers: { 'Content-Type': 'application/json', 'X-Api-Key': this.apiKey } }) } @@ -58,7 +58,7 @@ class Folder { this.collectionId = collectionId this.apiKey = process.env.POSTMAN_API_KEY this.axios = axios.create({ - timeout: 10000, + timeout: 1000 * 60, // 60 seconds headers: { 'Content-Type': 'application/json', 'X-Api-Key': this.apiKey } }) } @@ -120,7 +120,7 @@ class Request { this.collectionId = collectionId this.apiKey = process.env.POSTMAN_API_KEY this.axios = axios.create({ - timeout: 10000, + timeout: 1000 * 60, // 60 seconds headers: { 'Content-Type': 'application/json', 'X-Api-Key': this.apiKey } }) } @@ -183,7 +183,7 @@ class Response { this.collectionId = collectionId this.apiKey = process.env.POSTMAN_API_KEY this.axios = axios.create({ - timeout: 10000, + timeout: 1000 * 60, // 60 seconds headers: { 'Content-Type': 'application/json', 'X-Api-Key': this.apiKey } }) }