()
| 63 | cprint(textval, colval) |
| 64 | |
| 65 | def createConfig(): |
| 66 | privKeyName = path+"/jwttool_custom_private_RSA.pem" |
| 67 | pubkeyName = path+"/jwttool_custom_public_RSA.pem" |
| 68 | ecprivKeyName = path+"/jwttool_custom_private_EC.pem" |
| 69 | ecpubkeyName = path+"/jwttool_custom_public_EC.pem" |
| 70 | jwksName = path+"/jwttool_custom_jwks.json" |
| 71 | proxyHost = "127.0.0.1" |
| 72 | config = configparser.ConfigParser(allow_no_value=True) |
| 73 | config.optionxform = str |
| 74 | config['crypto'] = {'pubkey': pubkeyName, |
| 75 | 'privkey': privKeyName, |
| 76 | 'ecpubkey': ecpubkeyName, |
| 77 | 'ecprivkey': ecprivKeyName, |
| 78 | 'jwks': jwksName} |
| 79 | config['customising'] = {'useragent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) jwt_tool', |
| 80 | 'jwks_kid': 'jwt_tool'} |
| 81 | if (os.path.isfile(privKeyName)) and (os.path.isfile(pubkeyName)) and (os.path.isfile(ecprivKeyName)) and (os.path.isfile(ecpubkeyName)) and (os.path.isfile(jwksName)): |
| 82 | cprintc("Found existing Public and Private Keys - using these...", "cyan") |
| 83 | origjwks = open(jwksName, "r").read() |
| 84 | jwks_b64 = base64.b64encode(origjwks.encode('ascii')) |
| 85 | else: |
| 86 | # gen RSA keypair |
| 87 | pubKey, privKey = newRSAKeyPair() |
| 88 | with open(privKeyName, 'w') as test_priv_out: |
| 89 | test_priv_out.write(privKey.decode()) |
| 90 | with open(pubkeyName, 'w') as test_pub_out: |
| 91 | test_pub_out.write(pubKey.decode()) |
| 92 | # gen EC keypair |
| 93 | ecpubKey, ecprivKey = newECKeyPair() |
| 94 | with open(ecprivKeyName, 'w') as ectest_priv_out: |
| 95 | ectest_priv_out.write(ecprivKey) |
| 96 | with open(ecpubkeyName, 'w') as ectest_pub_out: |
| 97 | ectest_pub_out.write(ecpubKey) |
| 98 | # gen jwks |
| 99 | new_key = RSA.importKey(pubKey) |
| 100 | n = base64.urlsafe_b64encode(new_key.n.to_bytes(256, byteorder='big')) |
| 101 | e = base64.urlsafe_b64encode(new_key.e.to_bytes(3, byteorder='big')) |
| 102 | jwksbuild = buildJWKS(n, e, "jwt_tool") |
| 103 | jwksout = {"keys": []} |
| 104 | jwksout["keys"].append(jwksbuild) |
| 105 | fulljwks = json.dumps(jwksout,separators=(",",":"), indent=4) |
| 106 | with open(jwksName, 'w') as test_jwks_out: |
| 107 | test_jwks_out.write(fulljwks) |
| 108 | jwks_b64 = base64.urlsafe_b64encode(fulljwks.encode('ascii')) |
| 109 | config['services'] = {'jwt_tool_version': jwttoolvers, |
| 110 | '# To disable the proxy option set this value to: False (no quotes). For Docker installations with a Windows host OS set this to: "host.docker.internal:8080"': None, 'proxy': proxyHost+':8080', |
| 111 | '# To disable following redirects set this value to: False (no quotes)': None, 'redir': 'True', |
| 112 | '# Set this to the URL you are hosting your custom JWKS file (jwttool_custom_jwks.json) - your own server, or maybe use this cheeky reflective URL (https://httpbin.org/base64/{base64-encoded_JWKS_here})': None, |
| 113 | 'jwksloc': '', |
| 114 | 'jwksdynamic': 'https://httpbin.org/base64/'+jwks_b64.decode(), |
| 115 | '# Set this to the base URL of a Collaborator server, somewhere you can read live logs, a Request Bin etc.': None, 'httplistener': ''} |
| 116 | config['input'] = {'wordlist': 'jwt-common.txt', |
| 117 | 'commonHeaders': 'common-headers.txt', |
| 118 | 'commonPayloads': 'common-payloads.txt'} |
| 119 | config['argvals'] = {'# Set at runtime - changes here are ignored': None, |
| 120 | 'sigType': '', |
| 121 | 'targetUrl': '', |
| 122 | 'rate': str(DEFAULT_RATE_LIMIT), |
no test coverage detected