1
$\begingroup$

"Skatteetaten" is the Norwegian tax authority.

We're currently trying to implement signing of messages for digital cash registry systems and i'm not able to reproduce the desired signed data.

Went back and forth with different types of padding and hashing algorithms, still unable to reproduce the desired return data.

I'm using their validation tool hosted here on github. Trying to get a private key using RSA 1024 to work (Form in Validator.html).

Example private key:

-----BEGIN RSA PRIVATE KEY-----
MIICXwIBAAKBgQDag84L+pT6OlFZ8kav08ixPdugo6bsqOICJrl8TzGY87Iek9K1
dgbz2sr7r0OBl2/ndz0CoxiyKoiLc5YY6wy5Qg1qNRCc4C71r2A7N+vjhfkSSoS7
RQekuhKSMJ1Wp8RfXB/AccWPdqb0Mm1TjklSizptJAANppC12fijFVTocQIDAQAB
AoGBAMSsIQXzEaduWc4lG64hZd7xF/4rjZAwKMta41OZS8CohkazMdEVXAibglqp
Uo8PKC8iyQzYkt+5HJC3Bf+DfzyMMty5NPJVpNK1fr0ftz1TfAK7A0I5PWOq9DPL
pjNmz8DIGCfoMOsg1plfh2oprqK36shpWzG1jzXizui4u+aBAkEA/A6M8fM01L5r
xeGtppKEY8EtaSImnBc09kONP1vPqexNUA8cORqZn3J1GKhv90zk79IWdTrzPN4C
ZTHGpGR/eQJBAN3u7HyT/HqvvIhZksqKS+DTbjYaKGr3KxiAEAKU0PeQOBD5TQds
JVstZ2vGSbAsCU6VNEh8eQfTpxzy59S2mrkCQQCM8P3zFNGH3GqbHdRh/i+1MAHa
ddQtF/Tvd1p2ATqfg5i/mZNogu0/8Vp0zUq+d+rUBx+zsaDteh7QwwKWTfPRAkEA
x01W5pFnPS4wWypFnsoPVjnJUaCwB08sTnZC6m6GMqw7DVM0j6PY8EaYB7ssVZ9W
RFHNgAL4FcVG38Jr2ySZUQJBAOPa7ScbGi7XTiV3TStW2rhmd9CyKnOeSdjIejGm
R4xrannBqg+ikWXuW0cnuGk2a2a/ymHXq1pSCTFAa2VeryA=
-----END RSA PRIVATE KEY-----

Example public key:

-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDag84L+pT6OlFZ8kav08ixPdug
o6bsqOICJrl8TzGY87Iek9K1dgbz2sr7r0OBl2/ndz0CoxiyKoiLc5YY6wy5Qg1q
NRCc4C71r2A7N+vjhfkSSoS7RQekuhKSMJ1Wp8RfXB/AccWPdqb0Mm1TjklSizpt
JAANppC12fijFVTocQIDAQAB
-----END PUBLIC KEY-----

When using these keys with the signing data:

0;2014-01-24;23:59:59;123456789;1250.00;1000.00

Performing signing with sha1WithRSAEncryption i get the signed data:

gs1HumV5FxfeUum3Ws9s7ZsczPEtXUq+5/5MgYcbUb3hP9CJ2eg9d6Bm+d+D8HtbfLB3fCV8pfXo1JaluJ0JGtwLzyyC2uLDR+qvxRbCbly4W0/Ab8jPuF2KJHEPT9HLtbfwMEclMdyK+xp+OPwOvCCnREV43KMwisMGaB4TziA=

Which is base64 of the signature.

I've tried various PHP-crypto libraries and the openssl commandline tool to reproduce this signature and i can't just get the desired output.

If their validation library is not broken i must be missing something and all the possible combinations i've tried has not yielded the correct result...

Help would be appreciated to say the least.

$\endgroup$
2
  • $\begingroup$ Might be more appropriate to security stackexchange. $\endgroup$
    – kodlu
    Commented Nov 28, 2018 at 20:13
  • $\begingroup$ Did you try to sha1 the text and sign the generated signature? SIGN(SHA1("0;2014-01-24;23:59:59;123456789;1250.00;1000.00")) basically $\endgroup$
    – camp0
    Commented Nov 28, 2018 at 22:21

1 Answer 1

1
$\begingroup$

Obcrypto: note RSA-1024, although not actually broken, is no longer considered to provide an adequate safety margin and is prohibited or deprecated in most applications. For example CABforum began phasing it out in 2014, and Chrome and Firefox warned for it.

$ printf '0;2014-01-24;23:59:59;123456789;1250.00;1000.00' \
> |openssl sha1 -sign cry64393.key |openssl base64 -A; echo
gs1HumV5FxfeUum3Ws9s7ZsczPEtXUq+5/5MgYcbUb3hP9CJ2eg9d6Bm+d+D8HtbfLB3fCV8pfXo1JaluJ0JGtwLzyyC2uLDR+qvxRbCbly4W0/Ab8jPuF2KJHEPT9HLtbfwMEclMdyK+xp+OPwOvCCnREV43KMwisMGaB4TziA=
$ # or
$ printf '0;2014-01-24;23:59:59;123456789;1250.00;1000.00' |openssl sha1 -binary \
> |openssl pkeyutl -sign -inkey cry64393.key -pkeyopt digest:sha1 |openssl base64 -A; echo
gs1HumV5FxfeUum3Ws9s7ZsczPEtXUq+5/5MgYcbUb3hP9CJ2eg9d6Bm+d+D8HtbfLB3fCV8pfXo1JaluJ0JGtwLzyyC2uLDR+qvxRbCbly4W0/Ab8jPuF2KJHEPT9HLtbfwMEclMdyK+xp+OPwOvCCnREV43KMwisMGaB4TziA=

Both rsautl -sign and pkeyutl -sign with RSA key default to SSA-PKCS1-v1_5, but if you want you can specify -pkcs or -pkeyopt rsa_padding_mode:pkcs1 respectively. openssl sha1 is an abbreviation for openssl dgst -sha1 and openssl base64 for openssl enc -a.

(I can try for PHP also if you need it but that will take longer to set up.)

ADDED: I should have noted this only works because RSASSA-PKCS1-v1_5 is deterministic, which is unusual. Most other public-key signature schemes, and essentially all public-key encryption schemes (and symmetric encryption schemes also), when executed multiple times on the same data (and key) produce results which are all different but valid, so it is futile to try to reproduce or compare outputs.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.