From 591ced7c06ad0b9ad4452826b7e3334ade5580a9 Mon Sep 17 00:00:00 2001 From: Bsian Date: Mon, 30 Dec 2019 16:57:34 +0000 Subject: [PATCH] Trim newlines --- src/commands/cwg_updatecert.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/commands/cwg_updatecert.ts b/src/commands/cwg_updatecert.ts index 7f2b6aa..13d0c25 100644 --- a/src/commands/cwg_updatecert.ts +++ b/src/commands/cwg_updatecert.ts @@ -46,18 +46,18 @@ export default class CWG_UpdateCert extends Command { } public isValidCertificateChain(cert: string) { - if (!cert.startsWith('-----BEGIN CERTIFICATE-----')) return false; - if (!cert.endsWith('-----END CERTIFICATE-----')) return false; - if (this.checkOccurance(cert, '-----BEGIN CERTIFICATE-----') !== 2) return false; - if (this.checkOccurance(cert, '-----END CERTIFICATE-----') !== 2) return false; + if (!cert.replace(/^\s+|\s+$/g, '').startsWith('-----BEGIN CERTIFICATE-----')) return false; + if (!cert.replace(/^\s+|\s+$/g, '').endsWith('-----END CERTIFICATE-----')) return false; + if (this.checkOccurance(cert.replace(/^\s+|\s+$/g, ''), '-----BEGIN CERTIFICATE-----') !== 2) return false; + if (this.checkOccurance(cert.replace(/^\s+|\s+$/g, ''), '-----END CERTIFICATE-----') !== 2) return false; return true; } public isValidPrivateKey(key: string) { - if (!key.startsWith('-----BEGIN PRIVATE KEY-----')) return false; - if (!key.endsWith('-----END PRIVATE KEY-----')) return false; - if (this.checkOccurance(key, '-----BEGIN PRIVATE KEY-----') !== 1) return false; - if (this.checkOccurance(key, '-----END PRIVATE KEY-----') !== 1) return false; + if (!key.replace(/^\s+|\s+$/g, '').startsWith('-----BEGIN PRIVATE KEY-----')) return false; + if (!key.replace(/^\s+|\s+$/g, '').endsWith('-----END PRIVATE KEY-----')) return false; + if (this.checkOccurance(key.replace(/^\s+|\s+$/g, ''), '-----BEGIN PRIVATE KEY-----') !== 1) return false; + if (this.checkOccurance(key.replace(/^\s+|\s+$/g, ''), '-----END PRIVATE KEY-----') !== 1) return false; return true; } }