(ssg-wsg) No start line - pem

Have the following errors regarding PEM file using API with “Authentication” = “Certificate”
On Postman:
PEM routines:OPENSSL_internal:NO_START_LINE
On github node js sample:
node:_tls_common:155
context.setCert(cert);
^
Error: error:0909006C:PEM routines:get_name:no start line
at setCerts (node:_tls_common:155:13)
at Object.createSecureContext (node:_tls_common:210:7)
at Object.connect (node:_tls_wrap:1591:48)
at Agent.createConnection (node:https:129:22)
at Agent.createSocket (node:_http_agent:323:26)
at Agent.addRequest (node:_http_agent:274:10)
at new ClientRequest (node:_http_client:314:16)
at Object.request (node:https:313:10)
at Object.<anonymous> (/Users/kthxbai/Downloads/index.js:25:7)
at Module._compile (node:internal/modules/cjs/loader:1108:14) {
library: 'PEM routines',
function: 'get_name',
reason: 'no start line',
code: 'ERR_OSSL_PEM_NO_START_LINE'
}

I believe your certificate PEM file does not have the following lines which lead to the error.
-----BEGIN CERTIFICATE-----
...<your cert>...
-----END CERTIFICATE-----

Related

Paramiko No such file or directory: '-----BEGIN RSA PRIVATE KEY-----\n'

I am coming across issues using the SSHHook class in a DAG.
The error is
File "/usr/local/airflow/.local/lib/python3.7/site-packages/paramiko/pkey.py", line 307, in _read_private_key_file
with open(filename, "r") as f:
FileNotFoundError: [Errno 2] No such file or directory: '-----BEGIN RSA PRIVATE KEY-----\n'
What I am doing is taking a PEM key from AWS Secrets Manager and writing it to a file-like object using StringIO.
secrets_manager_hook = SecretsManagerHook()
sm_client = secrets_manager_hook.get_conn()
secret = sm_client.get_secret_value(SecretId='<SECRET>')
pem_key_value = secret["SecretString"]
with StringIO(initial_value=pem_key_value) as pem_file:
ssh_hook=SSHHook(ssh_conn_id=None, remote_host=<HOST>, username='ec2-user', key_file=pem_file)
ssh_hook_conn=ssh_hook.get_conn()
ssh_hook.exec_ssh_client_command(ssh_client=ssh_hook_conn, command='echo Hello', get_pty=False)
My PEM key that I uploaded as just a plain text secret looks like this
-----BEGIN RSA PRIVATE KEY-----
######
...
...
######
-----END RSA PRIVATE KEY-----
If I print the secret value retrieved from the Boto3 client it is a similar output.
I'm not sure of what the error is related to. Do I explicitly need new line characters \n at the end of every line? How can I implement that? StringIO seems like it already has newline='\n' as a default parameter.
The key_file takes file path. It does not accept a file-like object.
The only way to provide in-memory key is using private_key "extra option" in connection specified by ssh_conn_id.

ESP32 firebase OAuth2.0 access token error -116

i'm trying to connect esp32 to firestore but an error appear on the serial monitor
Token info: type = OAuth2.0 access token, status = error
Token error: code: -116, message: mbedTLS, mbedtls_pk_parse_key: PK - Invalid key tag or value
i'm using source code from https://github.com/mobizt/Firebase-ESP-Client/blob/main/examples/Firestore/ImportDocuments/ImportDocuments.ino
Most likely you've not provided the private key string correctly (TLS libraries are rather picky about that), or the private key is not in correct format.
E.g. this is how you generate a 2048 bit RSA keypair in PKCS8 format (which is what the sample code appears to use):
$ ssh-keygen -t rsa -b 2048 -m PKCS8 -f testkey
This is how you add the resulting private key as a multiline raw string literal in C++:
const char PRIVATE_KEY[] = R"(-----BEGIN PRIVATE KEY-----
MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDhhA52G0UQGFk5
+WDGpWXgVHR6Bjpyq81HZ0SI9PQYTZa87b4qOysL8QkpeXiUR5Ltza1A5ceLERfy
2fpwhLIdHDmFN9dYQIN7ODf8dPRFVPT9ABegHDGzNWQJBuDe9ffVfF8DYeSlo7iq
vKUSeL2IpbTFn7Ccard68Wee3GueIm0GVi6V/HKhJYT4Cq6Fp8g/xVMdwAD6AFR8
8vBH1FERJn+6U89xdgewnjrw69jhlctziIdDxANedqTX/aEkchKcFhhmXehwsFfn
3gdToJBu0fClaTUvm0tYMRLaoUfAQ9t6J9TtPkA3ZZFzge7FZGl3lpFd6NOiiiQD
Fi9NLXx7AgMBAAECggEANNV1deIpqf2qWdS9AY0acxYWO8hdxSPO8h2Vhuisj00O
NbEVTluSWDfeR6M3xrWGDMSVBJFQ0JnunGzJKbdM61kDeNx+TSTAKQwgwbq8x8mB
pAxzfIVed3fYueysnk/OAmw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hxyzkV
PrYun0MrVLxiiwezSTxlyGw=
-----END PRIVATE KEY-----
)";

Unable to connect Corda node to Postgres with SSL

My Postgres DB in GCP (Google Cloud Platform) only accepts connections over SSL.
I tried the below inside my node.conf without any success:
dataSourceProperties {
dataSourceClassName = "org.postgresql.ds.PGSimpleDataSource"
dataSource.url = "jdbc:postgresql://db-private-ip:5432/my_node"
dataSource.ssl = true
dataSource.sslMode = verify-ca
dataSource.sslRootCert = "/opt/corda/db-certs/server-ca.pem"
dataSource.sslCert = "/opt/corda/db-certs/client-cert.pem"
dataSource.sslKey = "/opt/corda/db-certs/client-key.pem"
dataSource.user = my_node_db_user
dataSource.password = my_pass
}
I'm sure that the keys (sslMode, sslRootCert, sslCert, and sslKey) are acceptable in node.conf (even though they are not mentioned anywhere in Corda docs), because in the logs I didn't get any errors that those key are not recognized.
I get this error when I try to start the node:
[ERROR] 21:58:48+0000 [main] pool.HikariPool. - HikariPool-1 - Exception during pool initialization. [errorCode=zmhrwq, moreInformationAt=https://errors.corda.net/OS/4.3/zmhrwq]
[ERROR] 21:58:48+0000 [main] internal.NodeStartupLogging. - Could not connect to the database. Please check your JDBC connection URL, or the connectivity to the database.: Could not connect to the database. Please check your JDBC connection URL, or the connectivity to the database. [errorCode=18t70u2, moreInformationAt=https://errors.corda.net/OS/4.3/18t70u2]
I tried adding ?ssl=true to the end of the data source URL as suggested in (Azure Postgres Database requires SSL Connection from Corda) but that didn't fix the problem.
Also for the same values I'm able to use the psql client to connect my VM to the DB:
psql "sslmode=verify-ca sslrootcert=server-ca.pem sslcert=client-cert.pem sslkey=client-key.pem hostaddr=db-private-ip user=some-user dbname=some-pass"
Turns out the JDBC driver cannot read the key from a PEM file, it has to be converted to a DER file using:
openssl pkcs8 -topk8 -inform PEM -in client-key.pem -outform DER -nocrypt -out client-key.der
chmod 400 client-key.der
chown corda:corda client-key.der
More details here: https://github.com/pgjdbc/pgjdbc/issues/1364
So the correct config should look like this:
dataSourceProperties {
dataSourceClassName = "org.postgresql.ds.PGSimpleDataSource"
dataSource.url = "jdbc:postgresql://db-private-ip:5432/db-name"
dataSource.ssl = true
dataSource.sslMode = verify-ca
dataSource.sslRootCert = "/opt/corda/db-certs/server-ca.pem"
dataSource.sslCert = "/opt/corda/db-certs/client-cert.pem"
dataSource.sslKey = "/opt/corda/db-certs/client-key.der"
dataSource.user = db-user-name
dataSource.password = db-user-pass
}

How to read an encrypted private key in the form of BEGIN PRIVATE KEY?

I have a private key that is in the following format, unfortunately I can't share the actual key, so the base64 code is masked:
-----BEGIN PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: AES-128-ECB,4C425124E54FEA716FEE437A01473736
****************************************************************
****************************************************************
****************************************************************
****************************************************************
****************************************************************
****************************************************************
****************************************************************
****************************************************************
****************************************************************
****************************************************************
****************************************************************
****************************************************************
****************************************************************
**********************==
-----END PRIVATE KEY-----
So I have little application that comes from 2010, written by Huawei called CardManufactureFileDecrypt that uses the private key, a certificate and the password / passphrase to successfully decrypt files that contain vouchers, so from that I can deduce that the file is intact, also that the password or passphrase I have is correct.
So my question is does anyone know how to read an encrypted private key in the form of BEGIN PRIVATE KEY? Or perhaps what libraries from about 10 years ago would have produced / consumed keys in this style?
When I try to read the private key with openssl I get the following error(s):
$ openssl rsa -in PrivateKey_E8.p8 -out PrivateKey_E8_unencrypted.p8
unable to load Private Key
139978370384320:error:0906B082:PEM routines:PEM_get_EVP_CIPHER_INFO:unexpected dek iv:../crypto/pem/pem_lib.c:551:
Or:
$ openssl pkcs8 -in PrivateKey_E8.p8 -out PrivateKey_E8_unencrypted.p8
Error reading key
140719466078656:error:0909006C:PEM routines:get_name:no start line:../crypto/pem/pem_lib.c:745:Expecting: ENCRYPTED PRIVATE KEY

Openssl cannot decrypt message using PuttyGen private key

I've created public and private keys using PuttyGen then the public key was used to encrypt a message.
I am now trying to decrypt such message using the private key with the following command:
echo [my encrypted message] | openssl enc -d -base64 -A | openssl rsautl -decrypt -inkey ~/.ssh/private.ppk
but I get the error:
unable to load Private Key
6870300:error:0906D06C:PEM routines:PEM_read_bio:no start line:pem_lib.c:707:Expecting: ANY PRIVATE KEY
The private key looks like this (actual key omitted):
PuTTY-User-Key-File-2: ssh-rsa
Encryption: none
Comment: rsa-key-20170724
Public-Lines: 6
[...]
Private-Lines: 14
[...]
Private-MAC: [...]
What's wrong?
Thanks to this guy I sorted it out.
I've reopened the private key with PuttyGen and exported as OpenSSH, then used this new file to decrypt the message.

Resources