Ubuntu dodanie certyfikatu ssl

0

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?

0

A jak dodawałeś cert na Windowsie?

0

pliki .cert i .key są dodane w projekcie normalnie i importowane w app.js, cała konfiguracja jest bez zmian

0

Gdzie otrzymujesz informację, że certyfikat jest nieważny? (W jakim scenariuszu).

0

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ł

0

openssl s_client -connect TWOJA_APLIKACJA:PORT -showcerts

czy pokazuje ten sam cert, który wrzuciles do ca-certificates ?

0
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

1

Czy to jest self-signed cert? (gra w 20 pytań :D)

0
yarel napisał(a):

Czy to jest self-signed cert? (gra w 20 pytań :D)

tak, dokładnie ten sam klucz działa na Windows

0

Pokaż co zwraca curl -v https://twoj-endpoint. Może to kwestia firefoxa z dobraniem się do certyfikatów systemowych.

0
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
    <
<!doctype html> <html lang="en"> <head> <script type="module" src="/@vite/client"></script> <meta charset="utf-8"> <title>Natours</title> <base href="/"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="icon" type="image/x-icon" href="favicon.ico"> <link rel="preconnect" href="https://fonts.googleapis.com"> <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin=""> <link href="https://fonts.googleapis.com/css2?family=Lato:ital,wght@0,300;0,400;0,700;1,300&amp;family=Open+Sans:wght@300&amp;family=Poppins:wght@400;700&amp;display=swap" rel="stylesheet"> <link rel="stylesheet" href="styles.css"></head> <body> <app-root></app-root> <script src="polyfills.js" type="module"></script><script src="main.js" type="module"></script></body> </html> * TLSv1.2 (IN), TLS header, Supplemental data (23): * Connection #0 to host localhost left intact
0

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

0

ehh kolejny błąd This is not a certificate authority certificate, so it can’t be imported into the certificate authority list.

0

stworzyłem nowy certyfikat, kraj PL i dalej to samo xd

0

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:'

screenshot-20240320205148.png

Pewni pokaże Ci CA:FALSE, a firefox ma jakieś dodatkowe checki przy imporcie certyfikatu.

0

nie zwraca nic

0

Spróbuj wygenerować certa letsencrypta toolem certbot.

0
yarel napisał(a):

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:'

screenshot-20240320205148.png

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?

4

@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)
  1. Zapisać jako generate_CA_and_server_certs.sh
  2. Nadać uprawnienia chmod +x generate_CA_and_server_certs.sh
  3. Dostosować konfigurację (np. dodać nazwę domeny/ustawić na pustą), dodać listę hostów.
  4. 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 "$@"

0

@yarel: dzięki wielkie! teraz wszystko śmiga 😀

1 użytkowników online, w tym zalogowanych: 0, gości: 1