Skip to main content

OpenSSL generate certificate with endianess,encoding and charset



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!


Answer




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"

Comments

Popular posts from this blog

linux - Awstats - outputting stats for merged Access_logs only producing stats for one server's log

I've been attempting this for two weeks and I've accessed countless number of sites on this issue and it seems there is something I'm not getting here and I'm at a lost. I manged to figure out how to merge logs from two servers together. (Taking care to only merge the matching domains together) The logs from the first server span from 15 Dec 2012 to 8 April 2014 The logs from the second server span from 2 Mar 2014 to 9 April 2014 I was able to successfully merge them using the logresolvemerge.pl script simply enermerating each log and > out_putting_it_to_file Looking at the two logs from each server the format seems exactly the same. The problem I'm having is producing the stats page for the logs. The command I've boiled it down to is /usr/share/awstats/tools/awstats_buildstaticpages.pl -configdir=/home/User/Documents/conf/ -config=example.com awstatsprog=/usr/share/awstats/wwwroot/cgi-bin/awstats.pl dir=/home/User/Documents/parced -month=all -year=all...

iLO 3 Firmware Update (HP Proliant DL380 G7)

The iLO web interface allows me to upload a .bin file ( Obtain the firmware image (.bin) file from the Online ROM Flash Component for HP Integrated Lights-Out. ) The iLO web interface redirects me to a page in the HP support website ( http://www.hp.com/go/iLO ) where I am supposed to find this .bin firmware, but no luck for me. The support website is a mess and very slow, badly categorized and generally unusable. Where can I find this .bin file? The only related link I am able to find asks me about my server operating system (what does this have to do with the iLO?!) and lets me download an .iso with no .bin file And also a related question: what is the latest iLO 3 version? (for Proliant DL380 G7, not sure if the iLO is tied to the server model)

hp proliant - Smart Array P822 with HBA Mode?

We get an HP DL360 G8 with an Smart Array P822 controller. On that controller will come a HP StorageWorks D2700 . Does anybody know, that it is possible to run the Smart Array P822 in HBA mode? I found only information about the P410i, who can run HBA. If this is not supported, what you think about the LSI 9207-8e controller? Will this fit good in that setup? The Hardware we get is used but all original from HP. The StorageWorks has 25 x 900 GB SAS 10K disks. Because the disks are not new I would like to use only 22 for raid6, and the rest for spare (I need to see if the disk count is optimal or not for zfs). It would be nice if I'm not stick to SAS in future. As OS I would like to install debian stretch with zfs 0.71 as file system and software raid. I have see that hp has an page for debian to. I would like to use hba mode because it is recommend, that zfs know at most as possible about the disk, and I'm independent from the raid controller. For us zfs have many benefits, ...