Skip to content

Commit

Permalink
Merge pull request #28 from mt89vein/AR5-6225
Browse files Browse the repository at this point in the history
  • Loading branch information
AndTem authored May 31, 2022
2 parents db2d49d + 9f2f036 commit ee6eca8
Show file tree
Hide file tree
Showing 25 changed files with 247 additions and 272 deletions.
2 changes: 1 addition & 1 deletion examples/cryptopro-cades/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@
},
"scripts": {
"build:prod": "webpack --mode=production --config webpack.config.js",
"dev": "webpack serve --mode=development"
"dev": "webpack serve --mode=development --port 8081"
}
}
2 changes: 1 addition & 1 deletion examples/cryptopro-cades/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
name="description"
content="Web site created using create-react-app"
/>
<title>React App</title>
<title>@astral/cryptopro-cades</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
Expand Down
31 changes: 21 additions & 10 deletions examples/cryptopro-cades/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,35 @@ const CryptoApp = () => {
const systemInfo = await getSystemInfo();
setVersionInfo(systemInfo);
} catch (error) {
window.alert(error);
outputError(error);
window.alert(error?.toString());
}
}
async function fetchCertificates() {
const fetchedCertificates = await getCertificates(STORE_TYPE.ALL);
try {
const fetchedCertificates = await getCertificates(STORE_TYPE.ALL);

setCertificates(fetchedCertificates);
setCertificates(fetchedCertificates);

// автоматически берем первый валидный серт если еще выбран
if (!selectedCertificate) {
setSelectedCertificate(
fetchedCertificates.find((c) => c.isGost && c.hasPrivateKey)
);
// автоматически берем первый валидный серт если еще выбран
if (!selectedCertificate) {
setSelectedCertificate(
fetchedCertificates.find((c) => c.isGost && c.hasPrivateKey)
);
}
} catch (error) {
outputError(error);
window.alert(error?.toString());
}
}
async function fetchCryptoProviders() {
const cryptoProviders = await getCryptoProviders();
setCryptoProviders(cryptoProviders);
try {
const cryptoProviders = await getCryptoProviders();
setCryptoProviders(cryptoProviders);
} catch (error) {
outputError(error);
window.alert(error?.toString());
}
}

if (showCryptoProviders) {
Expand Down
125 changes: 45 additions & 80 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions packages/cryptopro-cades/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
"lint": "eslint ./src --fix --quiet"
},
"dependencies": {
"buffer": "^6.0.3",
"pkijs": "^2.3.1",
"asn1js": "^3.0.2"
"buffer": "6.0.3",
"pkijs": "3.0.3",
"asn1js": "3.0.5"
},
"devDependencies": {
"@types/node": "^17.0.33",
"copyfiles": "^2.4.1"
"@types/node": "17.0.36",
"copyfiles": "2.4.1"
},
"version": "1.2.0"
}
61 changes: 19 additions & 42 deletions packages/cryptopro-cades/src/Certificate.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { unwrap } from './api/internal/unwrap';
import { CAPICOM_ENCODING_TYPE } from './constants';
import { CryptoError } from './errors';
import { ICertificate } from './types';
Expand Down Expand Up @@ -157,49 +158,25 @@ export class Certificate {
}
const certificate = new Certificate(cert);

if (cert.SubjectName instanceof Promise) {
certificate.subjectName = await cert.SubjectName;
certificate.thumbprint = await cert.Thumbprint;
certificate.notAfter = await cert.ValidToDate;
certificate.notBefore = await cert.ValidFromDate;
certificate.certificateBase64Data = await cert.Export(
CAPICOM_ENCODING_TYPE.CAPICOM_ENCODE_BASE64
certificate.subjectName = await unwrap(cert.SubjectName);
certificate.thumbprint = await unwrap(cert.Thumbprint);
certificate.notAfter = await unwrap(cert.ValidToDate);
certificate.notBefore = await unwrap(cert.ValidFromDate);
certificate.certificateBase64Data = await unwrap(
cert.Export(CAPICOM_ENCODING_TYPE.CAPICOM_ENCODE_BASE64)
);
try {
certificate.hasPrivateKey = await unwrap(cert.HasPrivateKey());
const oPrivateKey = await unwrap(cert.PrivateKey);
certificate.providerName = await unwrap(oPrivateKey.ProviderName);
certificate.providerType = await unwrap(oPrivateKey.ProviderType);
} catch (error) {
// ошибка не критична, просто создаем ошибку (в дебаге оно залогируется само)
CryptoError.createCadesError(
error,
`Ошибка получения информации о приватном ключе сертификата ${certificate.thumbprint}.`
);
try {
certificate.hasPrivateKey = await cert.HasPrivateKey();
const oPrivateKey = await cert.PrivateKey;
certificate.providerName = await oPrivateKey.ProviderName;
certificate.providerType = await oPrivateKey.ProviderType;
} catch (error) {
// ошибка не критична, просто создаем ошибку (в дебаге оно залогируется само)
CryptoError.createCadesError(
error,
`Ошибка получения информации о приватном ключе сертификата ${certificate.thumbprint}.`
);
certificate.hasPrivateKey = false;
}
} else {
certificate.subjectName = cert.SubjectName;
certificate.thumbprint = cert.Thumbprint as string;
certificate.notAfter = cert.ValidToDate as Date;
certificate.notBefore = cert.ValidFromDate as Date;
certificate.certificateBase64Data = cert.Export(
CAPICOM_ENCODING_TYPE.CAPICOM_ENCODE_BASE64
);

try {
certificate.hasPrivateKey = cert.HasPrivateKey();
const oPrivateKey = cert.PrivateKey;
certificate.providerName = oPrivateKey.ProviderName;
certificate.providerType = oPrivateKey.ProviderType;
} catch (error) {
// ошибка не критична, просто создаем ошибку (в дебаге оно залогируется само)
CryptoError.createCadesError(
error,
`Ошибка получения информации о приватном ключе сертификата ${certificate.thumbprint}.`
);
certificate.hasPrivateKey = false;
}
certificate.hasPrivateKey = false;
}

parseCertificate(certificate);
Expand Down
Loading

0 comments on commit ee6eca8

Please sign in to comment.