I have to add ssl (https) for a website, I was given a SSL.CSR and a SSL.KEY file. I 'dos2unix'ed them (because they have trailing ^M) and copied them to the server(CSR -> mywebsite.crt, KEY -> mywebsite.key). I did the following modification to nginx.conf:
## -60,8 +60,13 ##
}
server {
- listen 80;
+ listen 443;
server_name ...;
+ ssl on;
+ ssl_certificate mywebsite.crt;
+ ssl_certificate_key mywebsite.key;
+ ssl_session_cache shared:SSL:10m;
+ ssl_session_timeout 10m;
# Set the max size for file uploads to 500Mb
client_max_body_size 500M;
Error happens when I restart nginx:
nginx: [emerg] PEM_read_bio_X509_AUX("/etc/nginx/mywebsite.crt") failed (SSL: error:0906D06C:PEM routines:PEM_read_bio:no start line:Expecting: TRUSTED CERTIFICATE)
I figure it's because the first line of mywebsite.crt file contains 'REQUEST', so I remove 'REQUEST' from the first and last of the lines, and restart nginx again, and hit another error:
nginx: [emerg] PEM_read_bio_X509_AUX("/etc/nginx/mywebsite.crt") failed (SSL: error:0D0680A8:asn1 encoding routines:ASN1_CHECK_TLEN:wrong tag error:0D06C03A:asn1 encoding routines:ASN1_D2I_EX_PRIMITIVE:nested asn1 error error:0D08303A:asn1 encoding routines:ASN1_TEMPLATE_NOEXP_D2I:nested asn1 error:Field=algorithm, Type=X509_ALGOR error:0D08303A:asn1 encoding routines:ASN1_TEMPLATE_NOEXP_D2I:nested asn1 error:Field=signature, Type=X509_CINF error:0D08303A:asn1 encoding routines:ASN1_TEMPLATE_NOEXP_D2I:nested asn1 error:Field=cert_info, Type=X509 error:0906700D:PEM routines:PEM_ASN1_read_bio:ASN1 lib)
Any idea?
You should never share your private key. You should consider the key you posted here compromised and generate a new key and signing request.
You have a certificate request and not an actual signed certificate. You provide the request ('CSR') to the signing party. They use that request to create a signed certificate ('CRT') which they then make available to you. The key is never disclosed to anyone.
FYI, you can validate the keys just calling:
openssl x509 -noout -text -in your.crt
openssl rsa -noout -text -in your.key
In my case this error proved rather subtle: the BEGIN block started with 4 dashes, not 5. ---- vs -----. Sadly the validation tool error messages aren't very specific.
I came across this issue while searching online for SSL: error:0906D06C:PEM routines:PEM_read_bio:no start line:Expecting: TRUSTED CERTIFICATE
I got this error after running:
nginx -t
The problem I had was that cert.pem and cert.key was missing
-----BEGIN CERTIFICATE-----
-----END CERTIFICATE-----
The steps on the NGINX site for combining your public certificate with an intermediate certificate use cat to combine the two files. But if your public cert file does not end in a new line, the -----BEGIN CERTIFICATE----- line of the intermediate cert will be appended to the end of the -----END CERTIFICATE----- line of the public certificate, leading to an invalid chained certificate file. Manually separating these two lines can correct the issue.
I configured the certificates wrongly in gitlab.rb file.
A simple error took long to realize.
nginx['ssl_certificate'] = "/etc/gitlab/ssl/self-ssl.crt"
nginx['ssl_certificate'] = "/etc/gitlab/ssl/self-ssl.key"
Instead of
nginx['ssl_certificate'] = "/etc/gitlab/ssl/self-ssl.crt"
nginx['ssl_certificate_key'] = "/etc/gitlab/ssl/self-ssl.key"
I had the same problem, the reason was that the lines -----END CERTIFICATE----- of one certificate and -----BEGIN CERTIFICATE----- of another one happened to be on the same line, so basically:
-----END CERTIFICATE----------BEGIN CERTIFICATE-----
this happened after I merged a few crt files in a bundle through command line and between files there was no newline added, which corrupted the whole crt file.
fixed it by splitting the line
Because I was working in a different structure, I had copied the .crt and .key files from one place to another and then faced the same problem.
Actually, the problem is very simple. Had to set permissions again after copying.
In short, I solved the problem by changing the owner of the file.
sudo chown -R $USER:$USER /path/to/.key/file
(development only)
Related
Unable to crack why this is happening. Certificate bundle file seems proper but receiving PEM routines:PEM_read_bio:bad end line
-----BEGIN CERTIFICATE-----
MIIEizCCA3OgAwIBAgIQDI7gyQ1qiRWIBAYe4kH5rzANBgkqhkiG9w0BAQsFADBh
MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3
d3cuZGlnaWNlcnQuY29tMSAwHgYDVQQDExdEaWdpQ2VydCBHbG9iYWwgUm9vdCBH
MjAeFw0xMzA4MDExMjAwMDBaFw0yODA4MDExMjAw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aT0AC9aHesO3ewPj2
dZ12uYf+QYB6z13jAMZbAuabeGLJ3LhimnftiQjXS8X9Q9ViIyfEBFltcT8jW+rZ
8uckJ2/0lYDblizkVIvP6hnZf1WZUXoOLRg9eFhSvGNoVwvdRLNXSmDmyHBwW4co
atc7TlJFGa8kBpJIERqLrqwYElesA8u49L3KJg6nwd3jM+/AVTANlVlOnAM2BvjA
jxSZnE0qnsHhfTuvcqdFuhOWKU4Z0BqYBvQ3lBetoxi6PrABDJXWKTUgNX31EGDk
92hiHuwZ4STyhxGs6QiA1213PQJWENMASDASDDDAA
-----END CERTIFICATE-----
-----BEGIN CERTIFICATE-----
MIIEizCCA3OgAwIBAgIQDI7gyQ1qiRWIBAYe4kH5rzANBgkqhkiG9w0BAQsFADBh
MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3
d3cuZGlnaWNlcnQuY29tMSAwHgYDVQQDExdEaWdpQ2VydCBHbG9iYWwgUm9vdCBH
MjAeFw0xMzA4MDExMjAwMDBaFw0yODA4MDExMjAwMDBaMEQxCzAJBgNVBAYTAlVT
MRUwEwYDVQQKEwxEaWdpQ2VydCBJbmMxHjAcBgNVBAMTFURpZ2lDZXJ0IEdsb2Jh
CTq4G+zb43X1T77nJgSOI9pq/TqCwtukZ7u9VLL3JAq3Wdy2moKLvvC8tVmRzkAe
0xQCkRKIjbBG80MSyDX/R4uYgj6ZiNT/Zg6GI6RofgqgpDdssLc0XIRQEotxIZcK
zP3pGJ9FCbMHmMLLyuBd+uCWvVcF2ogYAawufChS/PT61D9rqzPRS5I2uqa3tmIT
44JhJgWhBnFMb7AGQkvNq9KNS9dd3GWc17H/dXa1enoxzWjE0hBdFjxPhUb0W3wi
8o34/m8Fxw==
-----END CERTIFICATE-----
Configuration file
server {
listen 443 ssl;
ssl_certificate /etc/nginx/bundle.crt;
ssl_certificate_key /etc/nginx/abc-private.key;
server_name localhost;
location / {
index index.html;
}
error_log /var/log/nginx/auth-api-error.log;
access_log /var/log/nginx/auth-api-access.log;
}
Error in /var/log/nginx/error.log while starting nginx
2020/01/07 17:13:32 [emerg] 4267#4267: cannot load certificate "/etc/nginx/bundle.crt": PEM_read_bio_X509() failed (SSL: error:0906D066:PEM routines:PEM_read_bio:bad end line)
The first certificate block has had the invalid characters 1213PQJWENMASDASDDDAA appended to its last line. Remove those and that cert can be parsed correctly. But it is a CA cert, specifically an intermediate cert for C=US, O=DigiCert Inc, CN=DigiCert Global CA G2, and not a valid server cert as the first cert in an nginx cert file should be.
The second block starts with the same first 5 lines (encoding 240 bytes) as the first block, perhaps copied, but the rest of it, although valid base64, appears to encode garbage and when combined doesn't produce anything even remotely resembling a valid cert. Remove it entirely. Then before the current first cert insert an actual server cert issued by that DigiCert intermediate if you have such; otherwise throw this away entirely and get correct certs from DigiCert or some other CA.
Sometimes, during initial SSL certificate installation or its renewal, the concatenation command corrupts certificate codes and reloading Nginx’s configuration files results in this error:
If we open a file with concatenated certificate codes, we can see that closing tag -----END CERTIFICATE----- of one certificate and opening tag -----BEGIN CERTIFICATE----- of another one are joined in one line:
The issue fix is quite simple: use a text editor of your choice (for example, Nano or vim on Linux-based operating systems, Notepad on Windows, Textedit on Mac OS X) and create a line break between the two certificate codes, so that -----BEGIN CERTIFICATE----- tag starts with the next line:
Make sure that you count five dashes at the start and end of a footer and a header. Save the file and exit the text editor.
The Nginx configuration file can be reloaded with one of the following commands:
nginx -s reload
or
service nginx reload
The server should serve HTTPS from now on without any issues.
REFERENCE:
https://www.namecheap.com/support/knowledgebase/article.aspx/9855/2238/nginxapache-error-0906d066pem-routinespem_read_biobad-end-line/
I'm trying to set up a SSL certificate on a site using nginx web server. In the past, I generated SSL certs from Let's Encrypt/Certbot with no issues. This time, I purchased a .com domain and a Positive SSL certificate from MyDomain.com. MyDomain.com doesn't provide a .zip file or ca-bundle file for the cert (i.e., there doesn't appear to be an intermediate certificate or root certificate). Instead, it gives me two plaintext lines of code to manually copy: one for Certificate and one for Key.
The Certificate line contains -----BEGIN CERTIFICATE----- and -----END CERTIFICATE-----
The Key line contains -----BEGIN RSA PRIVATE KEY----- and -----END RSA PRIVATE KEY-----
I paste each of these lines into its own text editor file (using Atom on Ubuntu 18.0) and save as .crt and .key, respectively. (I was told by MyDomain.com support that the Certificate should be .crt, but who knows?)
I then add these file paths to my nginx site config file as below:
ssl_certificate /etc/ssl/certs/mysite.com.crt;
ssl_certificate_key /etc/ssl/private/mysite.com.key;
However, nginx fails on restart and when I check the config file I get the following:
$ sudo nginx -t
nginx: [emerg] PEM_read_bio_X509_AUX("/etc/ssl/certs/mysite.com.crt") failed (SSL: error:0909006C:PEM routines:get_name:no start line:Expecting: TRUSTED CERTIFICATE)
nginx: configuration file /etc/nginx/nginx.conf test failed
Some things I've tried:
Saving the Certificate as a .pem = same error.
Manually adding the word TRUSTED to the certificate's beginning and ending = same error.
Trying to convert the file based on its encoding:
$ sudo openssl x509 -in /etc/ssl/certs/mysite.com.crt -out /etc/ssl/certs/mysite.com.pem -outform PEM
unable to load certificate
140561005191616:error:0909006C:PEM routines:get_name:no start line:../crypto/pem/pem_lib.c:745:Expecting: TRUSTED CERTIFICATE
$ sudo openssl x509 -in /etc/ssl/certs/mysite.com.crt -inform der -outform pem -out /etc/ssl/certs/mysite.com.pem
unable to load certificate
139831375835584:error:0D0680A8:asn1 encoding routines:asn1_check_tlen:wrong tag:../crypto/asn1/tasn_dec.c:1130:
139831375835584:error:0D07803A:asn1 encoding routines:asn1_item_embed_d2i:nested asn1 error:../crypto/asn1/tasn_dec.c:290:Type=X509
$ sudo openssl x509 -inform DER -in /etc/ssl/certs/mysite.com.crt -out /etc/ssl/certs/mysite.com.pem -text
unable to load certificate
139993835831744:error:0D0680A8:asn1 encoding routines:asn1_check_tlen:wrong tag:../crypto/asn1/tasn_dec.c:1130:
139993835831744:error:0D07803A:asn1 encoding routines:asn1_item_embed_d2i:nested asn1 error:../crypto/asn1/tasn_dec.c:290:Type=X509
I'm not sure what to do from here. Has anyone successfully installed a SSL certificate on nginx using just a .crt file and .key file?
Should anyone see this and feel curious, I had to reach out to MyDomain.com support and ask for the certificate bundle. They got it to me (.crtc bundle as well as individual files for cert and intermediate cert) and now it works just fine on my nginx server. It wasn't going to work without those additional files.
I've got 3 files:
AddTrustExternalCARoot.crt
COMODORSAAddTrustCA.crt
COMODORSADomainValidationSecureServerCA.crt
and also a keystore. How can I create a .pem file out of these? I was trying to put its content to a file called .pem, but nginx says
SSL: error:0B080074:x509 certificate
routines:X509_check_private_key:key values mismatch
Also those file haven't got any attributes. Only -----BEGIN CERTIFICATE----- , key and -----END CERTIFICATE-----.
You are missing a certificate for your domain. After you get it, concatenate all those files together. This is your file to be used in nginx configuration.
cat yourdomain.crt COMODORSADomainValidationSecureServerCA.crt COMODORSAAddTrustCA.crt AddTrustExternalCARoot.crt > bundle.crt
Also don't forget to configure path to private key. It is a different file.
Question:
Is there anything special about the way nginx wants its .pem/.crt and .key files formated? I can't get nginx running... it always craps out complaining about the cert/key file.
Ask:
Anyone want to share with me a (sanitized) copy of their .pem/crt and .key file on a (non-production) system that is working fine? Or otherwise tell me what I am doing wrong (see below)
Errors:
After configuring nginx.conf to point to ssltest.cuddletech.com.crt and depositing the .crt (and key) file in /nginx/servers... and then run nginx to start the server, I get the following error:
nginx: [emerg] unexpected end of file, expecting ";" or "}" in /usr/local/etc/nginx/servers/ssltest.cuddletech.com.crt:63
Troubleshooting:
`
If I go in and put a ;at the end of the file (right after the second
-----END CERTIFICATE-----; (it's a bundle containing both the leaf and the intermediate ca). Now,it no longer complains about the unexpected end, but rather complains:
nginx: [emerg] unknown directive "-----BEGIN" in /usr/local/etc/nginx/servers/ssltest.cuddletech.com.crt:62
If I then go in and delete the -----BEGIN part, it continues to complain about the unknown directive... this time starting with the first few characters of the encoded cert.
Interestingly, If I change the file type to .pem (keeping the ; at the end, and update nginx.conf to look for the .pem). Now, it does not complain at all about the certificate file, but rather starts complaining the same way about the KEY file:
$ nginx: [emerg] unexpected end of file, expecting ";" or "}" in /usr/local/etc/nginx/servers/ssltest.cuddletech.com.key:28
Putting the ; or } at the end of the .key file makes nginx complain:
nginx: [emerg] unknown directive "-----BEGIN" in /usr/local/etc/nginx/servers/ssltest.cuddletech.com.key:27
Also interesting is that both time it complains about the -----BEGIN it indicates a line number at the end of the file, not at the beginning.
How I Generated The Cert and Key files:
I generated the cert using Hashicorp's Vault PKI backend (per this howto )
I cut and pasted the leaf and intermediate cert into one file and the private key into another file.
They look like this:
Certificate bundle:
-----BEGIN CERTIFICATE-----
MIIE/DCCAuSgAwIBAgIUIKX6kkLIidtRvnx0nafFH9SunaIwDQYJKoZIhvc
NAQELBQAwKTEnMCGA1UEAxMeQ3VkZGxldGVjaCBPcHMgSW50ZXJtZWRpYXRlIENBMB4X
DTE3MDkwOTAwMTgxNVoXDTE3MTAwOTAwMTg0NVowITEfMB0GA1UEAxMWc3NsdGVz
....
NW9I2ThBDp0uo7LcIO7hmHhNun6apGSlgf6Gj1L63dp
Fe+hoQpCNOGfoc2P+4uJZenqiax5dFqskiBVkQ7uyVFxf5ydF5pjzwF/QFFcKKok
SkRjCJmrVxD/7V6H8u+hSRJuXGXNIIuhhUmYhWoNZpnZEUyDPOuMWHjxq7ZfPHlO
A039BhLFI0msEBfk+DunhYA+xyBIhK0Lq3pqcc7zH9A=
-----END CERTIFICATE-----
-----BEGIN CERTIFICATE-----
MIIFpTCCA42gAwIBAgIUbXR6po8/oWmxgTVYuhxHDAM1prUwDQYJKoZIhvcNAQEL
BQAwHTEbMBkGA1UEAxMSQ3VkZGxldGVjaCBSb290IENBMB4XDTE3MDkwODIyNTI0
OFoXDTE4MDkwODIyNTMxOFowKTEnMCUGA1UEAxMeQ3VkZGxldGVjaCBPcHMgSW50
.....
ZXJtZWRpYXRlIENBMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAwuTe
h9gpV4RcibYNOptsDJHomUZaEkRs3ppGt1asnM5os7L17ExFS8PLSY0SbhB75Vo1
TLlgH2MkDGHbw5bcgY0fYXvKqk1y6JjLFBnmiGHe8mHt9XaWkbnwP/E7CttGr2GC
SaT7RxDN2pHXceTnmLOiz0Dk1ZpssldMVD1MQeSQspuBp9s2sWfXtkrLluPLOZH0
C1WXl+H/7giQggXPmMVLhnxPaaAwU0DNX0IZjzE1fqazBbrx36n7baVdUgRczkD2
Xiht8pnAdbUFdp8byeupDkPJ2vLyMLocvSO6z1m4+drXlgFPBLSgKXGvnw5A8b+S
dqKRe55MBNxpws0E4OjMVwVXlMctcLCogmx6jFYjWSJUQgKLHCi2JVWW6ajlKOfV
Gn/opA11kWKb
-----END CERTIFICATE-----
The Private Key file:
-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEAyWnbF5T5vIlrcVHG82S+u/GESnlhAiX6maUYmpQMVOGsmjWr
XOKFGQbFW796FgENrt1PzXlYT8/aKyT215KomxkC4bWV0daobC5p+fzusVyV51Si
.....
smzFwxewOYa4FU3KGgRlscBooaRumwpXid3IPwfsBzOCdNQ8zXyaqSZeStewxUBq
ZtMEDpD3q7noZQU85cQs4SlbOOscXEUMUaeKQDhC2FWW9qlM5NKU
-----END RSA PRIVATE KEY-----
The HTTPS server section of nginx.conf
# HTTPS server
#
server {
listen 443 ssl;
server_name ssltest.cuddletech.com;
ssl_certificate /usr/local/etc/nginx/servers/ssltest.cuddletech.com.pem;
ssl_certificate_key /usr/local/etc/nginx/servers/ssltest.cuddletech.com.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
location / {
root /user/share/nginx/html;
index index.html index.htm;
}
}
include servers/*;
}
My Set-up:
Mac OS X 10.12.6
nginx version: nginx/1.12.1
built by clang 8.1.0 (clang-802.0.42)
built with OpenSSL 1.1.0f 25 May 2017
TLS SNI support enabled
TIA for any advice!!!
Your problem us the include servers/*; statement. You are including everything in the servers directory as config. So the certificates also are being loaded as config
Either change it to
include servers/*.conf;
Or remove it if there are no configs you are including
HAProxy is unable to load .pem files generated by letsencrypt, why is this?
The error I'm seeing is:
parsing [/haproxy.cfg:37] : 'bind :443' : unable to load SSL private key from PEM file '/certs/cert0.pem'.
The contents of the PEM file is:
-----BEGIN CERTIFICATE-----
MIIFCjCCA/KgAwIBAgISATGh2D5ZMcKNqpIqViwd5EZOMA0GCSqGSIb3DQEBCwUA
MEoxCzAJBgNVBAYTAlVTMRYwFAYDVQQKEw1MZXQncyBFbmNyeXB0MSMwIQYDVQQD
ExpMZXQncyBFbmNyeXB0IEF1dGhvcml0eSBYMTAeFw0xNTEyMTcwOTIyMDBaFw0x
NjAzMTYwOTIyMDBaMB4xHDAaBgNVBAMTE3N0YWdpbmcubXV6aGFjay5jb20wggEi
MA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCrV1XqamfHm6tbDYAbnbjRxBw8
pxM/wPdO9RLUk5EmPnYy0XmPrbge93M5hh4qzMA7IGRxRa4xXjmj2nl4y6oLmRzF
nqHRBznh0D3u27dOmxk9vgWEGFO423T4W4DW5T6ukw+i2V5zxdtiu9tP7s8qsN7P
IxKQ8tPx8NB0PYXTg+DWhPQMZkX3Q63YEJrl6pR1kQ+shOg1WRw08/gfl8YCH0bj
AtbSPwwSNzNVylgA2IZX6mTrBYnbXJ5N63Ee/p1e+vw9fqxha4B4qPpNoByvgR27
cIGFjEoBzeS76awPzBnZLWNaVqM3E0YL9riQnAAgYPrqBIofV65GELBjwVRFAgMB
AAGjggIUMIICEDAOBgNVHQ8BAf8EBAMCBaAwHQYDVR0lBBYwFAYIKwYBBQUHAwEG
CCsGAQUFBwMCMAwGA1UdEwEB/wQCMAAwHQYDVR0OBBYEFC5MVU7RKuD07ZwP6kGT
49qPO2tFMB8GA1UdIwQYMBaAFKhKamMEfd265tE5t6ZFZe/zqOyhMHAGCCsGAQUF
BwEBBGQwYjAvBggrBgEFBQcwAYYjaHR0cDovL29jc3AuaW50LXgxLmxldHNlbmNy
eXB0Lm9yZy8wLwYI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ADggEBANHIIkus7+MJiZZQsY14cCoBG1hd
v0J20/FyWo5ppnfjL78S2k4s2GLRJ7iD9ZDKErndvbNFGcsW+9kKK/TnY21hp4Dd
ITv8S9ZYQ7oaoqs7HwhEMY9sibED4aXw09xrJZTC9zK1uIfW6t5dHQjuOWv+HHoW
ZnupyxpsEUlEaFb+/SCI4KCSBdAsYxAcsHYI5xxEI4LutHp6s3OT2FuO90WfdsIk
6q78OMSdn875bNjdBYAqxUp2/LEIHfDBkLoQz0hFJmwAbYahqKaLn73PAAm1X2kj
f1w8DdnkabOLGeOVcj9LQ+s67vBykx4anTjURkbqZslUEUsn2k5xeua2zUk=
-----END CERTIFICATE-----
The problem is that I was using the fullchain.pem file generated by letsencrypt. Instead, one should concatenate it together with 'privkey.pem' (also generated by letsencrypt) into a single .pem file.
I could only fix this by using cert.pem instead of fullchain.pem when concatenating.
cat cert.pem key.pem > haproxy_cert.pem
Taken from https://www.haproxy.com/blog/haproxy-ssl-termination/:
frontend www.mysite.com
bind 10.0.0.3:80
bind 10.0.0.3:443 ssl crt /etc/ssl/certs/mysite.pem
default_backend web_servers
The ssl parameter enables SSL termination for this listener. The crt parameter identifies the location of the PEM-formatted SSL certificate.
This certificate should contain both the public certificate and private key.
To be honest, according with my experience on deploying HA Proxy with TLS/SSL end-to-end with minimum 2 nodes as Backend servers, this statement is somewhat true. In fact, HA Proxy requires fullchain.pem (instead of cert.pem) + privkey.pem as a single file. Not using fullchain.pem will lead to messages on Systemd like unable to load cert or things like that.
In a nutshell, you shall do:
$ cat fullchain.pem privkey.pem > /etc/haproxy/mydomain_certs/mydomain.pem
And not:
$ cat cert.pem privkey.pem > /etc/haproxy/mydomain_certs/mydomain.pem
This artile has a valuable example.
Just adding the issue that I encountered. The cat command generated concatenated the files without a newline between them. I manually inserted a new line (using vim) and it worked.
Also in my case I got three files from the registrar: crt, ca-bundle, and p7b. I just want to add that all I needed was the private key file and the crt file (so ca-bundle and p7b were not used).