Cześć, przesiadłem się z Windowsa na Ubuntu i mam problem z dodaniem certyfikatu w aplikacji Node. Dostaję informację, że certyfikat jest nieważny mimo, że dada wygaśnięcia to niedziela, 31 października 2032 0832. Czy jakaś dodatkowa konfiguracja jest potrzebna?
A jak dodawałeś cert na Windowsie?
pliki .cert i .key są dodane w projekcie normalnie i importowane w app.js, cała konfiguracja jest bez zmian
Gdzie otrzymujesz informację, że certyfikat jest nieważny? (W jakim scenariuszu).
w przeglądarce jest widoczna taka informacja, wywala też błąd że strona not secure,
wrzucam plik crt do /usr/local/share/ca-certificates/ i odpalam sudo update-ca-certificates i nic to nie zmienia, plik /etc/ca-certificates.conf się zaaktualizował
openssl s_client -connect TWOJA_APLIKACJA:PORT -showcerts
czy pokazuje ten sam cert, który wrzuciles do ca-certificates ?
flinst-one napisał(a):
openssl s_client -connect TWOJA_APLIKACJA:PORT -showcerts
czy pokazuje ten sam cert, który wrzuciles do ca-certificates ?
tak, ten sam
Czy to jest self-signed cert? (gra w 20 pytań :D)
yarel napisał(a):
Czy to jest self-signed cert? (gra w 20 pytań :D)
tak, dokładnie ten sam klucz działa na Windows
Pokaż co zwraca curl -v https://twoj-endpoint
. Może to kwestia firefoxa z dobraniem się do certyfikatów systemowych.
yarel napisał(a):
Pokaż co zwraca
curl -v https://twoj-endpoint
. Może to kwestia firefoxa z dobraniem się do certyfikatów systemowych.
- Trying 127.0.0.1:4202...
- Connected to localhost (127.0.0.1) port 4202 (#0)
- ALPN, offering h2
- ALPN, offering http/1.1
- CAfile: /etc/ssl/certs/ca-certificates.crt
- CApath: /etc/ssl/certs
- TLSv1.0 (OUT), TLS header, Certificate Status (22):
- TLSv1.3 (OUT), TLS handshake, Client hello (1):
- TLSv1.2 (IN), TLS header, Certificate Status (22):
- TLSv1.3 (IN), TLS handshake, Server hello (2):
- TLSv1.2 (IN), TLS header, Finished (20):
- TLSv1.2 (IN), TLS header, Supplemental data (23):
- TLSv1.3 (IN), TLS handshake, Encrypted Extensions (8):
- TLSv1.2 (IN), TLS header, Supplemental data (23):
- TLSv1.3 (IN), TLS handshake, Certificate (11):
- TLSv1.2 (IN), TLS header, Supplemental data (23):
- TLSv1.3 (IN), TLS handshake, CERT verify (15):
- TLSv1.2 (IN), TLS header, Supplemental data (23):
- TLSv1.3 (IN), TLS handshake, Finished (20):
- TLSv1.2 (OUT), TLS header, Finished (20):
- TLSv1.3 (OUT), TLS change cipher, Change cipher spec (1):
- TLSv1.2 (OUT), TLS header, Supplemental data (23):
- TLSv1.3 (OUT), TLS handshake, Finished (20):
- SSL connection using TLSv1.3 / TLS_AES_256_GCM_SHA384
- ALPN, server accepted to use h2
- Server certificate:
- subject: C=IN; ST=India; L=India; O=My Organisation; OU=My Organisational Unit; emailAddress=[email protected]; CN=localhost
- start date: Feb 1 0732 2023 GMT
- expire date: Oct 31 0732 2032 GMT
- subjectAltName: host "localhost" matched cert's "localhost"
- issuer: C=IN; ST=India; L=India; O=My Organisation; OU=My Organisational Unit; emailAddress=[email protected]; CN=localhost
- SSL certificate verify ok.
- Using HTTP2, server supports multiplexing
- Connection state changed (HTTP/2 confirmed)
- Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
- TLSv1.2 (OUT), TLS header, Supplemental data (23):
- TLSv1.2 (OUT), TLS header, Supplemental data (23):
- TLSv1.2 (OUT), TLS header, Supplemental data (23):
- Using Stream ID: 1 (easy handle 0x5e315b2c4eb0)
- TLSv1.2 (OUT), TLS header, Supplemental data (23):
GET / HTTP/2
Host: localhost:4202
user-agent: curl/7.81.0
accept: /
- TLSv1.2 (IN), TLS header, Supplemental data (23):
- TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
- TLSv1.2 (IN), TLS header, Supplemental data (23):
- TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
- old SSL session ID is stale, removing
- TLSv1.2 (IN), TLS header, Supplemental data (23):
- Connection state changed (MAX_CONCURRENT_STREAMS == 4294967295)!
- TLSv1.2 (OUT), TLS header, Supplemental data (23):
- TLSv1.2 (IN), TLS header, Supplemental data (23):
- TLSv1.2 (IN), TLS header, Supplemental data (23):
< HTTP/2 200
< access-control-allow-origin: *
< content-type: text/html
< cache-control: no-cache
< date: Wed, 20 Mar 2024 1510 GMT
<
Wniosek z tego taki, że curl użył trusted CA:
CAfile: /etc/ssl/certs/ca-certificates.crt
CApath: /etc/ssl/certs
I zweryfikował ten cerytfikat aplikacji:
Server certificate:
subject: C=IN; ST=India; L=India; O=My Organisation; OU=My Organisational Unit; [email protected]; CN=localhost
start date: Feb 1 0732 2023 GMT
expire date: Oct 31 0732 2032 GMT
subjectAltName: host "localhost" matched cert's "localhost"
issuer: C=IN; ST=India; L=India; O=My Organisation; OU=My Organisational Unit; [email protected]; CN=localhost
SSL certificate verify ok.
Może Twój firefox nie lubi certyfikatów z Indii ;-) Albo oczekuje ich gdzie indziej niż ubuntu ma.
Firefox -> Options/Preferences -> Privacy & Security -> idziesz do sekcji Certificates -> View Certficiates -> odpala się menedżer certyfikatów -> zakładka Authorities -> Import CA i importuejsz tego *.crt
ehh kolejny błąd This is not a certificate authority certificate, so it can’t be imported into the certificate authority list.
stworzyłem nowy certyfikat, kraj PL i dalej to samo xd
Obstawiam, ze generujesz certyfikat CA z jakiegoś randomowego tutoriala, bez ustawienia basic constraints
i key usage
, w efekcie bardziej restrykcyjne walidacje nie pozwalają na użycie jako CA.
Możesz sprawdzić, czy Twój cert może być używany jako CA:
openssl x509 -in foobar.crt -noout -text | grep 'CA:'
Pewni pokaże Ci CA:FALSE
, a firefox ma jakieś dodatkowe checki przy imporcie certyfikatu.
nie zwraca nic
Spróbuj wygenerować certa letsencrypta toolem certbot.
yarel napisał(a):
Obstawiam, ze generujesz certyfikat CA z jakiegoś randomowego tutoriala, bez ustawienia
basic constraints
ikey usage
, w efekcie bardziej restrykcyjne walidacje nie pozwalają na użycie jako CA.Możesz sprawdzić, czy Twój cert może być używany jako CA:
openssl x509 -in foobar.crt -noout -text | grep 'CA:'
Pewni pokaże Ci
CA:FALSE
, a firefox ma jakieś dodatkowe checki przy imporcie certyfikatu.
a jakiś tutorial możesz polecić albo podać komendy to wygenerowania crt i key?
@rzeznik997 odgrzebałem swój stary skrypt i trochę go obciąłem o niepotrzebne Ci funkcjonalności. Generuje CA oraz wykorzystuje je do wygenerowania i podpisania certyfikatów serwerów. Potrzebujesz openssl'a i basha.
Wygenerowany CA dodajesz do trust store'a. Cert serwerowe do konfiguracji serwera.
- *. key - klucz prywatny
- *.crt - certyfikat
- *.csr - certificate signing request
- *.pem - bundle (tj. łańcuch certyfikacji: certyfikat serwera + certyfikat CA)
- Zapisać jako generate_CA_and_server_certs.sh
- Nadać uprawnienia
chmod +x generate_CA_and_server_certs.sh
- Dostosować konfigurację (np. dodać nazwę domeny/ustawić na pustą), dodać listę hostów.
- Uruchomić, np.
./generate_CA_and_server_certs.sh -d myDummyCerts
#!/usr/bin/env bash
# Script generates dedicated CA and creates signed (with that CA) certificates
# Result is stored in dedicated directory (default) or provided with -d <directory>
#############################################################
# Configuration
#############################################################
CA_ALIAS="rootCA"
# Common path in DN
COMMON_DN_PATH="/C=UK/ST=England/L=London/O=FOO/OU=BAR"
# Domain name, appearing in subject alternate name
DOMAIN_NAME="my.domain"
# Array of server names: ("hostname1" "hostname2" .... )
SERVER_NAMES=("hostname1")
# Default output directory
OUTPUT_DIR="workspace.$$"
# temporary config file
OPENSSL_CONF="my_openssl.cnf"
#############################################################
# end of configuration
#############################################################
# Parse command-line arguments
while getopts ":d:h" opt; do
case ${opt} in
d )
OUTPUT_DIR=$OPTARG
;;
h | \? )
echo "Usage: $0 [-d output_directory]"
echo " -d Specify the output directory (default is workspace.PID)"
echo " -h Display this help message"
exit 0
;;
esac
done
# Utility Functions
check_error() {
if [ $1 -ne 0 ]; then
echo "ERROR: $2" >&2
exit 1
fi
}
prepare_output_dir() {
echo "Preparing output directory: $1"
if [ ! -d "$1" ]; then
mkdir -p "$1"
else
rm -f "$1"/*.csr "$1"/*.pem "$1"/*.crt "$1"/*.cnf
fi
}
generate_openssl_config() {
local hostname="$1"
local domain="$2"
local sanDns=""
# Avoid trailing dot in case DOMAIN_NAME is empty
if [ -z "$domain" ]; then
sanDns="DNS.1 = $hostname"
else
sanDns="DNS.1 = $hostname.$domain"
fi
cat > "$OUTPUT_DIR/${OPENSSL_CONF}" <<- EOF
# OpenSSL configuration
[ req ]
default_bits = 2048
prompt = no
default_md = sha256
distinguished_name = req_distinguished_name
x509_extensions = v3_ca
[ req_distinguished_name ]
C = UK
ST = England
L = London
O = FOO
OU = BAR
CN = $1
[ v3_ca ]
subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid:always,issuer
basicConstraints = critical, CA:true
keyUsage = critical, digitalSignature, cRLSign, keyCertSign
[ v3_req ]
basicConstraints = critical,CA:FALSE
keyUsage = digitalSignature, keyEncipherment
extendedKeyUsage = clientAuth, serverAuth
subjectAltName = @alt_names
[ alt_names ]
$sanDns
EOF
}
generate_root_ca() {
echo "Generating root CA..."
openssl req -new -x509 -days 3650 -nodes -newkey rsa:4096 -subj "$1" \
-keyout "$OUTPUT_DIR/$2.key" -out "$OUTPUT_DIR/$2.crt"
check_error $? "Failed to generate root CA"
}
generate_server_cert() {
local server_name="$1"
local domain="$2"
local ca_alias="$3"
local server_dn="$4"
local san="${server_name}.${domain}"
echo "Generating server certificate for ${server_name}"
generate_openssl_config "${server_name}" "${domain}"
openssl req -new -nodes -newkey rsa:2048 -subj "${server_dn}" \
-keyout "$OUTPUT_DIR/${server_name}.key" -out "$OUTPUT_DIR/${server_name}.csr"
check_error $? "Failed to generate private key and CSR for ${server_name}"
openssl x509 -req -in "$OUTPUT_DIR/${server_name}.csr" -CA "$OUTPUT_DIR/${ca_alias}.crt" \
-CAkey "$OUTPUT_DIR/${ca_alias}.key" -CAcreateserial -out "$OUTPUT_DIR/${server_name}.crt" \
-days 1000 -sha256 -extfile "$OUTPUT_DIR/${OPENSSL_CONF}" -extensions v3_req
check_error $? "Failed to sign the certificate for ${server_name}"
cat "$OUTPUT_DIR/${server_name}.crt" "$OUTPUT_DIR/${ca_alias}.crt" > "$OUTPUT_DIR/${server_name}.pem"
}
list_certificate_details() {
echo "Listing certificate details..."
# CA Certificate
echo "CA Certificate (${CA_ALIAS}.crt):"
openssl x509 -in "$OUTPUT_DIR/${CA_ALIAS}.crt" -noout -text
echo "---------------------------------------"
# Server Certificates
for server in "${SERVER_NAMES[@]}"; do
echo "Server Certificate for ${server}:"
openssl x509 -in "$OUTPUT_DIR/${server}.crt" -noout -text
echo "---------------------------------------"
done
}
main() {
# Prepare output directory
prepare_output_dir "$OUTPUT_DIR"
# Generate Root CA
local cert_dn="${COMMON_DN_PATH}/CN=${CA_ALIAS}"
generate_root_ca "${cert_dn}" "${CA_ALIAS}"
# Generate server certificates and sign with the CA
for server in "${SERVER_NAMES[@]}"; do
local server_dn="${COMMON_DN_PATH}/CN=${server}"
generate_server_cert "${server}" "${DOMAIN_NAME}" "${CA_ALIAS}" "${server_dn}"
done
list_certificate_details
}
main "$@"
@yarel: dzięki wielkie! teraz wszystko śmiga