6

All of the articles I read online talk about creating a self-signed certificate for a domain you own.

I have Apache2 set up on an Ubuntu 16.04 server at home. My ISP gives me a dynamic IP so I use No-IP. I have ports opened on my router to re-direct traffic to my server.

I also access the web-server from home (inside the network).

So if I am outside my home network I'll use https://username.noip.me/ and if I am at home I will use https://homeserver/.

So how can I create a self-signed certificate for this situation? What do I put as the Common Name?

2
  • What is the purpose of a self-signed certificate in a case like this?
    – Ramhound
    May 6, 2016 at 19:18
  • I want SSL encryption but its for a short term personal use (9 months) so I don't want to buy a domain. May 6, 2016 at 19:47

4 Answers 4

3

What do I put as the Common Name?

You use a friendly name for the Common Name (CN) for two reasons. First, its displayed to users by tools, so you want something like Example Widgets, LLC. Second, hostnames always go in the Subject Alternate Name (SAN). Placing a hostname in the CN is deprecated by both the IETF and CA/B Forums.

For more rules and reasons, see How do you sign Certificate Signing Request with your Certification Authority and How to create a self-signed certificate with openssl?


So how can I create a self-signed certificate for this situation?

Use the openssl utility with a custom configuration file. Below is a sample one.

You should two things. First, change the DNS names list to username.noip.me and homeserver. Second, after changing the names you want in the certificate, run the following command:

openssl req -config example-com.conf -new -x509 -sha256 -newkey rsa:2048 -nodes \
    -keyout example-com.key.pem -days 365 -out example-com.cert.pem

Obviously, you can change the name of the configuration file from example-com.conf to anything you want.

Also, at the house, I run my own PKI. I have a Root CA that issues certificates for devices on my network when needed. All devices have the Root CA installed. My internal domain is called home.pvt. Hosts on the network are named, pine64.home.pvt, rpi3.home.pvt, solaris.home.pvt, windows10.home.pvt, etc. Everything works as expected.


Example Configuration File

# Self Signed (note the addition of -x509):
#     openssl req -config example-com.conf -new -x509 -sha256 -newkey rsa:2048 -nodes -keyout example-com.key.pem -days 365 -out example-com.cert.pem
# Signing Request (note the lack of -x509):
#     openssl req -config example-com.conf -new -newkey rsa:2048 -nodes -keyout example-com.key.pem -days 365 -out example-com.req.pem
# Print it:
#     openssl x509 -in example-com.cert.pem -text -noout
#     openssl req -in example-com.req.pem -text -noout

[ req ]
default_bits        = 2048
default_keyfile     = server-key.pem
distinguished_name  = subject
req_extensions      = req_ext
x509_extensions     = x509_ext
string_mask         = utf8only

# The Subject DN can be formed using X501 or RFC 4514 (see RFC 4519 for a description).
#   Its sort of a mashup. For example, RFC 4514 does not provide emailAddress.
[ subject ]
countryName         = Country Name (2 letter code)
countryName_default     = US

stateOrProvinceName     = State or Province Name (full name)
stateOrProvinceName_default = NY

localityName            = Locality Name (eg, city)
localityName_default        = New York

organizationName         = Organization Name (eg, company)
organizationName_default    = Example, LLC

# Use a friendly name here because its presented to the user. The server's DNS
#   names are placed in Subject Alternate Names. Plus, DNS names here is deprecated
#   by both IETF and CA/Browser Forums. If you place a DNS name here, then you 
#   must include the DNS name in the SAN too (otherwise, Chrome and others that
#   strictly follow the CA/Browser Baseline Requirements will fail).
commonName          = Common Name (e.g. server FQDN or YOUR name)
commonName_default      = Example Company

emailAddress            = Email Address
emailAddress_default        = [email protected]

# Section x509_ext is used when generating a self-signed certificate. I.e., openssl req -x509 ...
#  If RSA Key Transport bothers you, then remove keyEncipherment. TLS 1.3 is removing RSA
#  Key Transport in favor of exchanges with Forward Secrecy, like DHE and ECDHE.
[ x509_ext ]

subjectKeyIdentifier        = hash
authorityKeyIdentifier  = keyid,issuer

basicConstraints        = CA:FALSE
keyUsage            = digitalSignature, keyEncipherment
subjectAltName          = @alternate_names
nsComment           = "OpenSSL Generated Certificate"

# RFC 5280, Section 4.2.1.12 makes EKU optional
# CA/Browser Baseline Requirements, Appendix (B)(3)(G) makes me confused
# extendedKeyUsage  = serverAuth, clientAuth

# Section req_ext is used when generating a certificate signing request. I.e., openssl req ...
[ req_ext ]

subjectKeyIdentifier        = hash

basicConstraints        = CA:FALSE
keyUsage            = digitalSignature, keyEncipherment
subjectAltName          = @alternate_names
nsComment           = "OpenSSL Generated Certificate"

# RFC 5280, Section 4.2.1.12 makes EKU optional
# CA/Browser Baseline Requirements, Appendix (B)(3)(G) makes me confused
# extendedKeyUsage  = serverAuth, clientAuth

[ alternate_names ]

DNS.1       = example.com
DNS.2       = www.example.com
DNS.3       = mail.example.com
DNS.4       = ftp.example.com

# Add these if you need them. But usually you don't want them or
#   need them in production. You may need them for development.
# DNS.5       = localhost
# DNS.6       = localhost.localdomain
# DNS.7       = 127.0.0.1

# IPv6 localhost
# DNS.8     = ::1
# DNS.9     = fe80::1
2

To answer your actual question:

You need to look at Subject Alternate Names.

These allow a certificate to have more than one domain name assigned to them.

The recommendation is that you leave Common Name empty and list all FQDNs in the Subject Alternate Name.

Alternatively, you can place either of your names in the Common Name, but you must still list them all in Subject Alternate Names.

1

Suggest you spend $10 or less on a domain name and use a free Let's Encrypt certificate. You'll have fewer problems. You may be able to get a certificate using that noip.me domain as well.

Let's Encrypt is pretty easy to set up on a supported Linux distribution with Apache/Nginx, but you haven't said what OS you're using. If you edit your post above I may be able to give more guidance.

4
  • I edited with OS details. And getting a domain name is one option but considering I only need this for like 9 months I don't want to spend the money. If I was doing this long term then I would. There must be a way to do this within my configuration? May 6, 2016 at 18:33
  • Sure, just get a Let's Encrypt certificate on the dynamic domain, I don't see why it wouldn't work. The official Let's Encrypt client should work, if not then use the ACME client I link to on this page photographerstechsupport.com/tutorials/…
    – Tim
    May 6, 2016 at 18:40
  • Let's Encrypt isn't designed for internal host names. I don't know if it's even possible to get one validated.
    – Daniel B
    May 7, 2016 at 7:57
  • So long as DNS resolves and it can contact your web server I don't see why it wouldn't work. Completely internal, I agree, but if there's a route to it from the internet it should be ok.
    – Tim
    May 7, 2016 at 19:16
1

You could apply a trick and use a wildcard certificate for '*.noip.com'.

This requires you to use 'homeserver.noip.com' and have that address point to your local IP which you can do by adding an entry to the hosts file on the machines where you use 'homeserver.noip.com'.

'username.noip.com' would still be resolved in the usual way.

It is a somewhat "dirty approach" but looks efficient for your needs.

2
  • what would the entry in the hosts file look like? i didn't know this would work. May 8, 2016 at 14:51
  • The entry in the hosts file would be something like: 192.168.1.10 homeserver 192.168.1.10 homeserver.noip.me (every IP/name is on a new line - formatting in comments is not easy). On windows, the hosts file is generally located in C:\Windows\System32\drivers\etc and must be edited as an administrator. On *nix, you can find the hosts file in /etc/hosts and it must be edited as root.
    – le_top
    May 8, 2016 at 16:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .