Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | 1x 1x 1x 1x 1x 1x 1x 1x | const {cx_root} = await import("./cx_root.clas.mjs"); // zcl_abapgit_http_digest.clas.abap class zcl_abapgit_http_digest { static INTERNAL_TYPE = 'CLAS'; static INTERNAL_NAME = 'ZCL_ABAPGIT_HTTP_DIGEST'; static IMPLEMENTED_INTERFACES = []; static ATTRIBUTES = {"GV_NC": {"type": () => {return new abap.types.Numc({length: 8});}, "visibility": "I", "is_constant": " ", "is_class": "X"}, "MV_HA1": {"type": () => {return new abap.types.String({qualifiedName: "STRING"});}, "visibility": "I", "is_constant": " ", "is_class": " "}, "MV_USERNAME": {"type": () => {return new abap.types.String({qualifiedName: "STRING"});}, "visibility": "I", "is_constant": " ", "is_class": " "}, "MV_REALM": {"type": () => {return new abap.types.String({qualifiedName: "STRING"});}, "visibility": "I", "is_constant": " ", "is_class": " "}, "MV_QOP": {"type": () => {return new abap.types.String({qualifiedName: "STRING"});}, "visibility": "I", "is_constant": " ", "is_class": " "}, "MV_NONCE": {"type": () => {return new abap.types.String({qualifiedName: "STRING"});}, "visibility": "I", "is_constant": " ", "is_class": " "}}; static METHODS = {"MD5": {"visibility": "I", "parameters": {"RV_HASH": {"type": () => {return new abap.types.String({qualifiedName: "STRING"});}, "is_optional": " "}, "IV_DATA": {"type": () => {return new abap.types.String({qualifiedName: "STRING"});}, "is_optional": " "}}}, "HASH": {"visibility": "I", "parameters": {"RV_RESPONSE": {"type": () => {return new abap.types.String({qualifiedName: "STRING"});}, "is_optional": " "}, "IV_QOP": {"type": () => {return new abap.types.String({qualifiedName: "STRING"});}, "is_optional": " "}, "IV_NONCE": {"type": () => {return new abap.types.String({qualifiedName: "STRING"});}, "is_optional": " "}, "IV_URI": {"type": () => {return new abap.types.String({qualifiedName: "STRING"});}, "is_optional": " "}, "IV_METHOD": {"type": () => {return new abap.types.String({qualifiedName: "STRING"});}, "is_optional": " "}, "IV_CNONSE": {"type": () => {return new abap.types.String({qualifiedName: "STRING"});}, "is_optional": " "}}}, "PARSE": {"visibility": "I", "parameters": {"II_CLIENT": {"type": () => {return new abap.types.ABAPObject({qualifiedName: "IF_HTTP_CLIENT", RTTIName: "\\INTERFACE=IF_HTTP_CLIENT"});}, "is_optional": " "}}}, "CONSTRUCTOR": {"visibility": "U", "parameters": {"II_CLIENT": {"type": () => {return new abap.types.ABAPObject({qualifiedName: "IF_HTTP_CLIENT", RTTIName: "\\INTERFACE=IF_HTTP_CLIENT"});}, "is_optional": " "}, "IV_USERNAME": {"type": () => {return new abap.types.String({qualifiedName: "STRING"});}, "is_optional": " "}, "IV_PASSWORD": {"type": () => {return new abap.types.String({qualifiedName: "STRING"});}, "is_optional": " "}}}, "RUN": {"visibility": "U", "parameters": {"II_CLIENT": {"type": () => {return new abap.types.ABAPObject({qualifiedName: "IF_HTTP_CLIENT", RTTIName: "\\INTERFACE=IF_HTTP_CLIENT"});}, "is_optional": " "}}}}; #gv_nc; #mv_ha1; #mv_username; #mv_realm; #mv_qop; #mv_nonce; constructor() { this.me = new abap.types.ABAPObject(); this.me.set(this); this.INTERNAL_ID = abap.internalIdCounter++; this.FRIENDS_ACCESS_INSTANCE = { "hash": this.#hash.bind(this), "parse": this.#parse.bind(this), "run": this.run.bind(this), }; this.gv_nc = zcl_abapgit_http_digest.gv_nc; this.#mv_ha1 = new abap.types.String({qualifiedName: "STRING"}); this.FRIENDS_ACCESS_INSTANCE["mv_ha1"] = this.#mv_ha1; this.#mv_username = new abap.types.String({qualifiedName: "STRING"}); this.FRIENDS_ACCESS_INSTANCE["mv_username"] = this.#mv_username; this.#mv_realm = new abap.types.String({qualifiedName: "STRING"}); this.FRIENDS_ACCESS_INSTANCE["mv_realm"] = this.#mv_realm; this.#mv_qop = new abap.types.String({qualifiedName: "STRING"}); this.FRIENDS_ACCESS_INSTANCE["mv_qop"] = this.#mv_qop; this.#mv_nonce = new abap.types.String({qualifiedName: "STRING"}); this.FRIENDS_ACCESS_INSTANCE["mv_nonce"] = this.#mv_nonce; } async constructor_(INPUT) { let ii_client = INPUT?.ii_client; if (ii_client?.getQualifiedName === undefined || ii_client.getQualifiedName() !== "IF_HTTP_CLIENT") { ii_client = undefined; } if (ii_client === undefined) { ii_client = new abap.types.ABAPObject({qualifiedName: "IF_HTTP_CLIENT", RTTIName: "\\INTERFACE=IF_HTTP_CLIENT"}).set(INPUT.ii_client); } let iv_username = INPUT?.iv_username; if (iv_username?.getQualifiedName === undefined || iv_username.getQualifiedName() !== "STRING") { iv_username = undefined; } if (iv_username === undefined) { iv_username = new abap.types.String({qualifiedName: "STRING"}).set(INPUT.iv_username); } let iv_password = INPUT?.iv_password; if (iv_password?.getQualifiedName === undefined || iv_password.getQualifiedName() !== "STRING") { iv_password = undefined; } if (iv_password === undefined) { iv_password = new abap.types.String({qualifiedName: "STRING"}).set(INPUT.iv_password); } await this.#parse({ii_client: ii_client}); this.#mv_ha1.set((await this.md5({iv_data: new abap.types.String().set(`${abap.templateFormatting(iv_username)}:${abap.templateFormatting(this.#mv_realm)}:${abap.templateFormatting(iv_password)}`)}))); this.#mv_username.set(iv_username); return this; } async #hash(INPUT) { let rv_response = new abap.types.String({qualifiedName: "STRING"}); let iv_qop = INPUT?.iv_qop; if (iv_qop?.getQualifiedName === undefined || iv_qop.getQualifiedName() !== "STRING") { iv_qop = undefined; } if (iv_qop === undefined) { iv_qop = new abap.types.String({qualifiedName: "STRING"}).set(INPUT.iv_qop); } let iv_nonce = INPUT?.iv_nonce; if (iv_nonce?.getQualifiedName === undefined || iv_nonce.getQualifiedName() !== "STRING") { iv_nonce = undefined; } if (iv_nonce === undefined) { iv_nonce = new abap.types.String({qualifiedName: "STRING"}).set(INPUT.iv_nonce); } let iv_uri = INPUT?.iv_uri; if (iv_uri?.getQualifiedName === undefined || iv_uri.getQualifiedName() !== "STRING") { iv_uri = undefined; } if (iv_uri === undefined) { iv_uri = new abap.types.String({qualifiedName: "STRING"}).set(INPUT.iv_uri); } let iv_method = INPUT?.iv_method; if (iv_method?.getQualifiedName === undefined || iv_method.getQualifiedName() !== "STRING") { iv_method = undefined; } if (iv_method === undefined) { iv_method = new abap.types.String({qualifiedName: "STRING"}).set(INPUT.iv_method); } let iv_cnonse = INPUT?.iv_cnonse; if (iv_cnonse?.getQualifiedName === undefined || iv_cnonse.getQualifiedName() !== "STRING") { iv_cnonse = undefined; } if (iv_cnonse === undefined) { iv_cnonse = new abap.types.String({qualifiedName: "STRING"}).set(INPUT.iv_cnonse); } let lv_ha2 = new abap.types.String({qualifiedName: "STRING"}); lv_ha2.set((await this.md5({iv_data: new abap.types.String().set(`${abap.templateFormatting(iv_method)}:${abap.templateFormatting(iv_uri)}`)}))); abap.statements.assert(abap.compare.initial(iv_cnonse) === false); rv_response.set((await this.md5({iv_data: new abap.types.String().set(`${abap.templateFormatting(this.#mv_ha1)}:${abap.templateFormatting(iv_nonce)}:${abap.templateFormatting(zcl_abapgit_http_digest.gv_nc)}:${abap.templateFormatting(iv_cnonse)}:${abap.templateFormatting(iv_qop)}:${abap.templateFormatting(lv_ha2)}`)}))); return rv_response; } async md5(INPUT) { return zcl_abapgit_http_digest.md5(INPUT); } static async md5(INPUT) { let rv_hash = new abap.types.String({qualifiedName: "STRING"}); let iv_data = INPUT?.iv_data; if (iv_data?.getQualifiedName === undefined || iv_data.getQualifiedName() !== "STRING") { iv_data = undefined; } if (iv_data === undefined) { iv_data = new abap.types.String({qualifiedName: "STRING"}).set(INPUT.iv_data); } let lv_xstr = new abap.types.XString({qualifiedName: "XSTRING"}); let lv_hash = new abap.types.XString({qualifiedName: "XSTRING"}); let lv_empty = new abap.types.XString({qualifiedName: "XSTRING"}); lv_xstr.set((await abap.Classes['ZCL_ABAPGIT_CONVERT'].string_to_xstring_utf8({iv_string: iv_data}))); try { await abap.Classes['CL_ABAP_HMAC'].calculate_hmac_for_raw({if_algorithm: abap.CharacterFactory.get(3, 'MD5'), if_key: lv_empty, if_data: lv_xstr, ef_hmacxstring: lv_hash}); } catch (e) { if ((abap.Classes['CX_ABAP_MESSAGE_DIGEST'] && e instanceof abap.Classes['CX_ABAP_MESSAGE_DIGEST'])) { await abap.Classes['ZCX_ABAPGIT_EXCEPTION'].raise({iv_text: abap.CharacterFactory.get(21, 'error calculating md5')}); } else { throw e; } } rv_hash.set(lv_hash); abap.statements.translate(rv_hash, "LOWER"); return rv_hash; } async #parse(INPUT) { let ii_client = INPUT?.ii_client; if (ii_client?.getQualifiedName === undefined || ii_client.getQualifiedName() !== "IF_HTTP_CLIENT") { ii_client = undefined; } if (ii_client === undefined) { ii_client = new abap.types.ABAPObject({qualifiedName: "IF_HTTP_CLIENT", RTTIName: "\\INTERFACE=IF_HTTP_CLIENT"}).set(INPUT.ii_client); } let lv_value = new abap.types.String({qualifiedName: "STRING"}); lv_value.set((await ii_client.get().if_http_client$response.get().if_http_entity$get_header_field({name: abap.CharacterFactory.get(16, 'www-authenticate')}))); abap.statements.find(lv_value, {regex: abap.CharacterFactory.get(16, 'realm="([\\w ]+)"'), submatches: [this.#mv_realm]}); abap.statements.find(lv_value, {regex: abap.CharacterFactory.get(11, 'qop="(\\w+)"'), submatches: [this.#mv_qop]}); abap.statements.find(lv_value, {regex: abap.CharacterFactory.get(20, 'nonce="([\\w=/+\\$]+)"'), submatches: [this.#mv_nonce]}); } async run(INPUT) { let ii_client = INPUT?.ii_client; if (ii_client?.getQualifiedName === undefined || ii_client.getQualifiedName() !== "IF_HTTP_CLIENT") { ii_client = undefined; } if (ii_client === undefined) { ii_client = new abap.types.ABAPObject({qualifiedName: "IF_HTTP_CLIENT", RTTIName: "\\INTERFACE=IF_HTTP_CLIENT"}).set(INPUT.ii_client); } let lv_response = new abap.types.String({qualifiedName: "STRING"}); let lv_method = new abap.types.String({qualifiedName: "STRING"}); let lv_cnonce = new abap.types.String({qualifiedName: "STRING"}); let lv_uri = new abap.types.String({qualifiedName: "STRING"}); let lv_auth = new abap.types.String({qualifiedName: "STRING"}); abap.statements.assert(abap.compare.initial(this.#mv_nonce) === false); lv_method.set((await ii_client.get().if_http_client$request.get().if_http_entity$get_header_field({name: abap.CharacterFactory.get(15, '~request_method')}))); lv_uri.set((await ii_client.get().if_http_client$request.get().if_http_entity$get_header_field({name: abap.CharacterFactory.get(12, '~request_uri')}))); if (abap.FunctionModules['GENERAL_GET_RANDOM_STRING'] === undefined) { if (abap.Classes['CX_SY_DYN_CALL_ILLEGAL_FUNC'.trimEnd()] === undefined) { throw "CX_SY_DYN_CALL_ILLEGAL_FUNC not found"; } else { throw new abap.Classes['CX_SY_DYN_CALL_ILLEGAL_FUNC'.trimEnd()]();} } await abap.FunctionModules['GENERAL_GET_RANDOM_STRING']({exporting: {number_chars: abap.IntegerFactory.get(24)}, importing: {random_string: lv_cnonce}}); lv_response.set((await this.#hash({iv_qop: this.#mv_qop, iv_nonce: this.#mv_nonce, iv_uri: lv_uri, iv_method: lv_method, iv_cnonse: lv_cnonce}))); lv_auth.set(new abap.types.String().set(`Digest username="${abap.templateFormatting(this.#mv_username)}", realm="${abap.templateFormatting(this.#mv_realm)}", nonce="${abap.templateFormatting(this.#mv_nonce)}", uri="${abap.templateFormatting(lv_uri)}", qop=${abap.templateFormatting(this.#mv_qop)}, nc=${abap.templateFormatting(zcl_abapgit_http_digest.gv_nc)}, cnonce="${abap.templateFormatting(lv_cnonce)}", response="${abap.templateFormatting(lv_response)}"`)); await ii_client.get().if_http_client$request.get().if_http_entity$set_header_field({name: abap.CharacterFactory.get(13, 'Authorization'), value: lv_auth}); } } abap.Classes['ZCL_ABAPGIT_HTTP_DIGEST'] = zcl_abapgit_http_digest; zcl_abapgit_http_digest.gv_nc = new abap.types.Numc({length: 8}); export {zcl_abapgit_http_digest}; |