Created
November 1, 2019 17:54
-
-
Save jcjones/79efe5a6fe2aad3145e1d5e6be765893 to your computer and use it in GitHub Desktop.
Broken RSA PKCS8 structure - missing the prime1 field of PKCS1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pkcs1 = { | |
"version": 0, | |
"modulus": 25919547779068344813557225018916459243888511060580538521317535335916939669305711198124884121889905971452025616014278206275340890512969518554057142602273923483999163870181876938187799162284290847100195363021806949618646246749945850028053399500856599964212551512723624622979641733723716683062556541446382026036719662605892702171703485093064473383644496568073302712792779146792258459955311804887040246129590180745167177685560045626455120174460475726780417816070155430314837988907034054380822924150908056421408653448071530817548866905564640574264813470442105775538969501246892411050963085070599532463413097543580760453193, | |
"publicExponent": 65537, | |
"privateExponent": 6861045132845227059914105614052561682148677691669609262978418343950548077927208719731914639769078364782485319538820793177359564347147339790893438971332957330979713670444408519213298440076718153340772222678827333597575035302471285018946097235773079270933355869855645512602817107841967697907582447793030431476561372029020840693003047830277442645408595897822393402430435683663351753252103807114340865617796587125991243245878778795655022702478470261006756923412842369418967378224833312446823234323818210214313849093066302434673658328873979344682940160656715114453916957628016142166150751544677936021478560345286591091025, | |
"prime1": 176684713366633502991599280561701949917228530172698960651613929401818382967215310276834169854279311945534769811903587902247611526858792951899763167236008720188244717705616949799996326732893180938347697719412930198465866894083610167882668901351692272642080245435055047172924940241673334088829142136965896645399, | |
"prime2": 146699435877530710599092081070170635240805658630013689016686118921159246178601036525553245401807587125889722341885791023098261307716306622263648164530051116132423046004224298618902784420546922819037049341046987599645165915365398384680170317939898258720825406834013181889162089722657009243869152008583544904607, | |
"exponent1": 58092408923573229205837638243184058117039845707940815174954254096928185851924187952534029510353092357025546178599852176902078721649652418138396580978706927424451793294179380110324257265977726518753012656330161892008216729995477850642167775246444986662366985498795583509806469815944840364162081797569939742665, | |
"exponent2": 10972742644180471235435698634450408989584957178453806301170260386522462498550471963139326013697007676444015120007387393308019545148928621425094271976537079379299293094171346137752131608549689727313114971234757972038094562111802232047579152212359144670178466275544083763685743378861782799234731268536499032949, | |
"coefficient": 83810930343614071672960153390338745817429423298764618140478803631860183610359228632940112767516397098283369745834895394053754904680010627356799352611424125741639374805045928162595124087483269480146952565470959534058932675813384887753914664293142134018371006863905572066222920794426375140551397810007678938867 | |
} | |
del pkcs1['prime1'] | |
import asn1tools | |
foo = asn1tools.compile_files('/tmp/pkcs8.asn') | |
encoded = foo.encode('RSAPrivateKey', pkcs1) | |
import binascii | |
pkcs8 = { | |
"version": 0, | |
"privateKeyAlgorithm": { | |
"algorithm": "1.2.840.113549.1.1.1", | |
"parameters": None, | |
}, | |
"privateKey": encoded | |
} | |
encodedpkcs8 = foo.encode('PrivateKeyInfo', pkcs8) | |
binascii.hexlify(encodedpkcs8).decode('utf-8') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Foo DEFINITIONS ::= BEGIN | |
PrivateKeyInfo ::= SEQUENCE { | |
version Version, | |
privateKeyAlgorithm PrivateKeyAlgorithmIdentifier, | |
privateKey PrivateKey | |
} | |
Version ::= INTEGER | |
PrivateKeyAlgorithmIdentifier ::= AlgorithmIdentifier | |
AlgorithmIdentifier ::= SEQUENCE { | |
algorithm OBJECT IDENTIFIER, | |
parameters NULL | |
} | |
PrivateKey ::= OCTET STRING | |
RSAPrivateKey ::= SEQUENCE { | |
version Version, | |
modulus INTEGER, -- n | |
publicExponent INTEGER, -- e | |
privateExponent INTEGER, -- d | |
-- prime1 INTEGER, | |
prime2 INTEGER, -- q | |
exponent1 INTEGER, -- d mod (p-1) | |
exponent2 INTEGER, -- d mod (q-1) | |
coefficient INTEGER, -- (inverse of q) mod p | |
otherPrimeInfos OtherPrimeInfos OPTIONAL | |
} | |
OtherPrimeInfos ::= SEQUENCE SIZE(1..MAX) OF OtherPrimeInfo | |
OtherPrimeInfo ::= SEQUENCE { | |
prime INTEGER, -- ri | |
exponent INTEGER, -- di | |
coefficient INTEGER -- ti | |
} | |
END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
asn1tools==0.146.6 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment