I'm having some trouble creating a certificate with the openssl commandline tool.

The specs for the private key are:

"A digital signature using an RSA 1024 bit key with a SHA-1 hash function (RSA-SHA1-1024)"

Creating it as follows

openssl genrsa -out rsa.key 1024

Generating the CSR

openssl req -new -key rsa.key -out csr.csr

The certificate has the following spec:

  • Format = x.509
  • Charset = UTF-8
  • Encoding = Base-64
  • Endianness = Little Endian
  • OAEP Padding = PKCS1 v1.5 padding
  • Private key size = 1024 bits
  • Hash Message Format = SHA-1

I've tried tons of combinations of the following:

openssl x509 -req -utf8 -enc base64 -pkcs -sha1 rsa:1024 -in csr.csr -signkey rsa.key -out server.crt

I can't get a large set of combination of the above command to work at all, always some parameter that breaks it.

According to the spec we're supposed to sign a RSA message digest with the given certificate. I'm a bit confused why and how we are supposed to do this, maybe its an erroneus specification?

signing Specification documentation

I'm using OpenSSL 1.1.0f 25 May 2017

The endianess i can't even find how to set it with the openssl commandline tool, any help here would be greatly appreciated!

  • What is this for? It feels like you might be misinterpreting documentation somewhere. Your first quote for example talks about a signature which you can create without a certificate and just the private key. The algorithm references are also considered fairly old and insecure at this point depending on the context. Nov 27 '18 at 19:49
  • Yes that's whats confusing me to, i'm updating the post with the picture given in the specification. I don't really need a self signed certificate to make an openssl signing but in the documentation it seems like i have to. Bit confused ...
    – JazzCat
    Nov 27 '18 at 21:45

Unless I'm reading it wrong, that doc seems to contradict itself. It talks about certificate creation and that self-signed certs are ok, but then later says the only thing they want you to send to the NTA is the public key. Signing the data doesn't require a certificate, just the private key. So I'm wondering why they don't just have you create a public/private keypair rather than a whole cert that is only ever going to sit on the box and never get used.

Here's how you'd create a simple RSA 1024 private key and extract the public key into its own file:

openssl genrsa -out rsa.key 1024
openssl rsa -in rsa.key -outform PEM -pubout -out rsa.pub

The rsa.pub file is what you'd send to NTA. I've never heard of anyone needing to deal with endianness explicitly with openssl. So I could be wrong, but you likely don't have to worry about it. The UTF8 charset likely only matters for actual certs with text fields like the Subject. Openssl outputs PEM files with ASCII encoding which is fine (and normal) because PEM is Base64 encoded. PKCS1 v1.5 padding is also standard.

So now that you've got your keys. Let's try signing their example data from section 2.2.5 of their doc. First, throw the data into a file to make it easier to use in examples.

echo -n 'signature_from_previous_receipt;2014-01-24;23:59:59;123456789;1250.00;1000.00' > data.txt

Display the SHA1 hash just to prove we've got data that matches the example

openssl dgst -sha1 data.txt

Hash and sign the data, convert it to base64 with no line breaks and save it to a file.

openssl dgst -sha1 -sign rsa.key data.txt | openssl base64 -A -out data.sig

Hypothetically, the text within data.sig is now what you'd use for "signature_for_this_receipt" from the example.

To verify, we can just do the following which should output "Verified OK".

openssl dgst -sha1 -verify rsa.pub -signature <(openssl base64 -d -A -in data.sig) data.txt

If for some reason you do need an actual certificate file, you can replace the first command that generates the private key with this one liner that will generate both the key and a self-signed cert. You still need the same second command to extract the public key.

openssl req -nodes -x509 -sha1 -utf8 -newkey rsa:1024 -keyout rsa.key -out server.crt -days 365 -subj "/CN=MyCert"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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