Skip to content

Commit

Permalink
Allow only ASCII printable chars in PKCS #12 pass
Browse files Browse the repository at this point in the history
Related: PeculiarVentures/PKI.js#404
Author-Change-Id: IB#1141363
  • Loading branch information
pboguslawski committed Apr 19, 2024
1 parent 951c82e commit 8ea0b78
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/lib/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export const CERTIFICATE_PEM_REGEXP = new RegExp(
'^\\n*-{5}BEGIN CERTIFICATE-{5}\\n([A-Za-z0-9+/=]+\\n)+-{5}END CERTIFICATE-{5}\\n*$',
''
);
export const PRINTABLE_ASCII_CHARACTERS_REGEXP = new RegExp('^[\x20-\x7E]*$', '');

// Settings defines application settings.
export type Settings = {
Expand Down
11 changes: 9 additions & 2 deletions src/lib/components/dashboard/Certificate.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ SPDX-FileCopyrightText: 2024 Informatyka Boguslawski sp. z o.o. sp.k. <https://w
bufferToHex,
downloadPKCS12,
getKeyIdentifier,
CERTIFICATE_PEM_REGEXP
CERTIFICATE_PEM_REGEXP,
PRINTABLE_ASCII_CHARACTERS_REGEXP
} from '$lib/common';
import { getCrypto, Certificate, PublicKeyInfo } from 'pkijs';
import { fromBER } from 'asn1js';
Expand Down Expand Up @@ -270,11 +271,17 @@ SPDX-FileCopyrightText: 2024 Informatyka Boguslawski sp. z o.o. sp.k. <https://w
generatePKCS12();
}}
variant="outlined"
disabled={!ownerId || !password || !keyPair || !certificate}
disabled={!ownerId ||
!password ||
!PRINTABLE_ASCII_CHARACTERS_REGEXP.test(password) ||
!keyPair ||
!certificate}
title={!ownerId
? $t('dashboard.ownerIdFieldCannotBeEmpty')
: !password
? $t('dashboard.passwordFieldCannotBeEmpty')
: !PRINTABLE_ASCII_CHARACTERS_REGEXP.test(password)
? $t('dashboard.passwordMayContainASCIIPrintableCharactersOnly')
: !keyPair
? $t('dashboard.keyMustBeAvailable')
: !certificate
Expand Down
3 changes: 2 additions & 1 deletion src/lib/i18n/en/dashboard.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
"ownerId": "Owner ID",
"ownerIdFieldCannotBeEmpty": "Owner ID field cannot be empty.",
"passwordFieldCannotBeEmpty": "Password field cannot be empty.",
"passwordForKeyEncryptionInFiles": "Password for the private key encryption in files. For better security use '<'a href=\"https://en.wikipedia.org/wiki/Password_strength\"'>'strong passwords'<'/a'>'.",
"passwordMayContainASCIIPrintableCharactersOnly": "Password may contain ASCII printable characters only.",
"passwordForKeyEncryptionInFiles": "Password for the private key encryption in files. For better security use '<'a href=\"https://en.wikipedia.org/wiki/Password_strength\"'>'strong passwords'<'/a'>'. Only '<'a href=\"https://en.wikipedia.org/wiki/Printable_characters#Printable_characters\"'>'ASCII printable characters'<'/a'>' are supported for PKCS #12 files.",
"pasteOrLoadCrt": "Paste or load certificate in PEM format.",
"plainKeyConfirmation": "Do you really want to download an unencrypted private key?",
"plainKeyConfirmationContent": "Encrypting the private key in a file further protects it from unauthorized access. In order to encrypt the private key in a file, you need to enter a password in the Password field, and currently this field is empty, which if you accept this download, will cause the private key to be unencrypted in the downloaded file. Do you really want to download a file with an unencrypted private key?",
Expand Down
3 changes: 2 additions & 1 deletion src/lib/i18n/pl/dashboard.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
"ownerId": "ID właściciela",
"ownerIdFieldCannotBeEmpty": "Pole ID właściciela nie może być puste.",
"passwordFieldCannotBeEmpty": "Pole hasło nie może być puste.",
"passwordForKeyEncryptionInFiles": "Hasło do szyfrowania klucza prywatnego w plikach. Dla lepszego bezpieczeństwa używaj '<'a href=\"https://pl.wikipedia.org/wiki/Mocne_has%C5%82o\"'>'silnych haseł'<'/a'>'.",
"passwordMayContainASCIIPrintableCharactersOnly": "Hasło może zawierać tylko drukowalne znaki ASCII.",
"passwordForKeyEncryptionInFiles": "Hasło do szyfrowania klucza prywatnego w plikach. Dla lepszego bezpieczeństwa używaj '<'a href=\"https://pl.wikipedia.org/wiki/Mocne_has%C5%82o\"'>'silnych haseł'<'/a'>'. Dla plików PKCS #12 wspierane są tylko '<'a href=\"https://pl.wikipedia.org/wiki/ASCII#Znaki_drukowalne\"'>'drukowalne znaki ASCII'<'/a'>'.",
"pasteOrLoadCrt": "Wklej lub załaduj certyfikat w formacie PEM.",
"plainKeyConfirmation": "Czy na pewno chcesz pobrać niezaszyfrowany klucz prywatny?",
"plainKeyConfirmationContent": "Zaszyfrowanie klucza prywatnego w pliku zabezpiecza go dodatkowo przed nieupoważnionym dostępem. W celu zaszyfrowania klucza prywatnego w pliku, należy podać hasło w polu Hasło a obecnie pole to jest puste co w przypadku akceptacji tego pobierania spowoduje, że klucz prywatny będzie niezaszyfrowany w pobranym pliku. Czy na pewno chcesz pobrać plik z niezaszyfrowanym kluczem prywatnym?",
Expand Down

0 comments on commit 8ea0b78

Please sign in to comment.