Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Smimedemo #196

Open
wants to merge 58 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
9f23902
First submission of a working CMS S/MIME encoding/decoding
Oct 3, 2018
fe5ca7c
Remove bundle.js, accidentally included.
Oct 3, 2018
6a4ba12
Changed line ending from LF to CRLF for windows users.
Oct 4, 2018
f55ec4e
Rename directory.
Oct 5, 2018
180ec21
Changes to be committed:
Oct 5, 2018
0a04ead
Transition from var to let. Renamed test file.
Oct 5, 2018
b776410
Switched from constructor calls to litteral calls where
Oct 10, 2018
0b0671e
Removing copied files from branch.
Oct 10, 2018
5f06dc0
Remove JSLint warnings. Must set following globals in JSLint:
Oct 17, 2018
73edf63
Implemented "use strict" in accordance with the environment
Oct 18, 2018
25e542c
Text box label will now appear above as a block rather than
Oct 18, 2018
0913807
Parsed certificate table generator now produces internal
Oct 19, 2018
be74514
Corrected a problem when clicking import certificates.
Oct 22, 2018
ab9b36d
Merge remote-tracking branch 'upstream/master' into smimedemo
Oct 22, 2018
6b21577
Corrected a key import problem.
Oct 22, 2018
257e2fe
Changed a configuration variable to make demo deployment
Oct 24, 2018
4f535e1
Merge branch 'smimedemo' of github.com:koolsys/PKI.js into smimedemo
Oct 24, 2018
2b7ff06
When exporting as PKCS12, the private key and first
Oct 24, 2018
ab3e7e4
Test Filename Update
Oct 26, 2018
da2e9ba
Merge branch 'smimedemo' of github.com:koolsys/PKI.js into smimedemo
Oct 26, 2018
dca10e8
Merge remote-tracking branch 'upstream/master' into smimedemo
Oct 26, 2018
c3bd664
Fixed a bug where encryption was pulling source data from an
Oct 27, 2018
2c55605
Merge branch 'smimedemo' of github.com:koolsys/PKI.js into smimedemo
Oct 27, 2018
61ed751
Trusted certificates are cleared from the internal array
Nov 1, 2018
7f65d91
Certificate tables are now cleared before appending new
Nov 1, 2018
2a1cf28
Fix problems with encryption example and OriginatorInfo class
YuryStrozhevsky Nov 5, 2018
685df09
Handle CryptoSubtle Better
Nov 7, 2018
f8a9c77
Typos on paragraph #288
kant Nov 10, 2018
163758f
Merge pull request #203 from kant/patch-1
YuryStrozhevsky Nov 11, 2018
fd4e9ac
Fix problem with getCrypto for old-style browsers
YuryStrozhevsky Nov 13, 2018
c9e2246
Merge remote-tracking branch 'origin/master'
YuryStrozhevsky Nov 13, 2018
578d0c3
Fix problem described in issue #206
YuryStrozhevsky Nov 19, 2018
69c9cac
Implementing example for OpenSSL encrypted keys, new tests and fixes
YuryStrozhevsky Nov 28, 2018
b165c18
Possible fix for issue #210
YuryStrozhevsky Nov 29, 2018
e31fdf1
Protections Against Wrong Types Added
Dec 5, 2018
2f647df
First submission of a working CMS S/MIME encoding/decoding
Oct 3, 2018
1382d78
Remove bundle.js, accidentally included.
Oct 3, 2018
9193fa2
Changed line ending from LF to CRLF for windows users.
Oct 4, 2018
62c7e7b
Rename directory.
Oct 5, 2018
1ac56ba
Changes to be committed:
Oct 5, 2018
06d1bc8
Transition from var to let. Renamed test file.
Oct 5, 2018
2cc828a
Switched from constructor calls to litteral calls where
Oct 10, 2018
139edb0
Removing copied files from branch.
Oct 10, 2018
915c317
Remove JSLint warnings. Must set following globals in JSLint:
Oct 17, 2018
eb916e5
Implemented "use strict" in accordance with the environment
Oct 18, 2018
2dc801a
Text box label will now appear above as a block rather than
Oct 18, 2018
2e72d96
Parsed certificate table generator now produces internal
Oct 19, 2018
ef10c03
Corrected a problem when clicking import certificates.
Oct 22, 2018
76b6478
Corrected a key import problem.
Oct 22, 2018
26675a2
Changed a configuration variable to make demo deployment
Oct 24, 2018
cd0115d
When exporting as PKCS12, the private key and first
Oct 24, 2018
0875363
Test Filename Update
Oct 26, 2018
54981d9
Fixed a bug where encryption was pulling source data from an
Oct 27, 2018
889c836
Trusted certificates are cleared from the internal array
Nov 1, 2018
88286db
Certificate tables are now cleared before appending new
Nov 1, 2018
948ed53
Handle CryptoSubtle Better
Nov 7, 2018
3f46af1
Protections Against Wrong Types Added
Dec 5, 2018
fc1ac16
Merge branch 'smimedemo' of github.com:koolsys/PKI.js into smimedemo
Dec 5, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ _**WARNING**_: if you would try to build PKI.js code for Node version <= 4 then

### How to use PKI.js ES6 files directly in browser

Currently there is a posibility to use ES6 modules directly from Web pages, without any transpilations (Babel, Rollup etc.). In order to do this all used files must point to direct or relative names and should be achivable via browser. Almost all moder browsers would support the "native ES6 modules". You could check [_**this link to caniuse site**_](https://caniuse.com/#feat=es6-module) for current status.
Currently there is a posibility to use ES6 modules directly from Web pages, without any transpilations (Babel, Rollup etc.). In order to do this all used files must point to direct or relative names and should be achievable via browser. Almost all modern browsers would support the "native ES6 modules". You could check [_**this link to caniuse site**_](https://caniuse.com/#feat=es6-module) for current status.

You could check [_**full-featured example here**_](https://github.com/PeculiarVentures/PKI.js/tree/master/examples/HowToUseES6DirectlyInBrowser). And please carefully read [_**this README**_](https://github.com/PeculiarVentures/PKI.js/tree/master/examples/HowToUseES6DirectlyInBrowser/README.md) before run it.

Expand Down
32 changes: 20 additions & 12 deletions examples/HowToEncryptCMSviaCertificate/es6.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
/* eslint-disable no-undef,no-unreachable */
import * as asn1js from "asn1js";
import { arrayBufferToString, stringToArrayBuffer, toBase64, fromBase64, isEqualBuffer } from "pvutils";
import { getCrypto, getAlgorithmParameters, setEngine } from "../../src/common";
import Certificate from "../../src/Certificate";
import EnvelopedData from "../../src/EnvelopedData";
import ContentInfo from "../../src/ContentInfo";
import AttributeTypeAndValue from "../../src/AttributeTypeAndValue";
import BasicConstraints from "../../src/BasicConstraints";
import Extension from "../../src/Extension";
import { getCrypto, getAlgorithmParameters, setEngine } from "../../src/common.js";
import Certificate from "../../src/Certificate.js";
import EnvelopedData from "../../src/EnvelopedData.js";
import ContentInfo from "../../src/ContentInfo.js";
import AttributeTypeAndValue from "../../src/AttributeTypeAndValue.js";
import BasicConstraints from "../../src/BasicConstraints.js";
import Extension from "../../src/Extension.js";
import OriginatorInfo from "../../src/OriginatorInfo.js";
import CertificateSet from "../../src/CertificateSet.js";
//<nodewebcryptoossl>
//*********************************************************************************
let certificateBuffer = new ArrayBuffer(0); // ArrayBuffer with loaded or created CERT
Expand Down Expand Up @@ -230,7 +232,13 @@ function envelopedEncryptInternal()
const certSimpl = new Certificate({ schema: asn1.result });
//endregion

const cmsEnveloped = new EnvelopedData();
const cmsEnveloped = new EnvelopedData({
originatorInfo: new OriginatorInfo({
certs: new CertificateSet({
certificates: [certSimpl]
})
})
});

cmsEnveloped.addRecipientByCertificate(certSimpl, { oaepHashAlgorithm: oaepHashAlg });

Expand All @@ -253,7 +261,7 @@ function envelopedEncrypt()
return Promise.resolve().then(() =>
{
// noinspection InnerHTMLJS
const encodedCertificate = document.getElementById("new_signed_data").innerHTML;
const encodedCertificate = document.getElementById("new_signed_data").value;
const clearEncodedCertificate = encodedCertificate.replace(/(-----(BEGIN|END)( NEW)? CERTIFICATE-----|\n)/g, "");
certificateBuffer = stringToArrayBuffer(fromBase64(clearEncodedCertificate));

Expand Down Expand Up @@ -303,17 +311,17 @@ function envelopedDecrypt()
return Promise.resolve().then(() =>
{
// noinspection InnerHTMLJS
const encodedCertificate = document.getElementById("new_signed_data").innerHTML;
const encodedCertificate = document.getElementById("new_signed_data").value;
const clearEncodedCertificate = encodedCertificate.replace(/(-----(BEGIN|END)( NEW)? CERTIFICATE-----|\n)/g, "");
certificateBuffer = stringToArrayBuffer(window.atob(clearEncodedCertificate));

// noinspection InnerHTMLJS
const encodedPrivateKey = document.getElementById("pkcs8_key").innerHTML;
const encodedPrivateKey = document.getElementById("pkcs8_key").value;
const clearPrivateKey = encodedPrivateKey.replace(/(-----(BEGIN|END)( NEW)? PRIVATE KEY-----|\n)/g, "");
privateKeyBuffer = stringToArrayBuffer(window.atob(clearPrivateKey));

// noinspection InnerHTMLJS
const encodedCMSEnveloped = document.getElementById("encrypted_content").innerHTML;
const encodedCMSEnveloped = document.getElementById("encrypted_content").value;
const clearEncodedCMSEnveloped = encodedCMSEnveloped.replace(/(-----(BEGIN|END)( NEW)? CMS-----|\n)/g, "");
cmsEnvelopedBuffer = stringToArrayBuffer(window.atob(clearEncodedCMSEnveloped));
}).then(() => envelopedDecryptInternal()).then(result =>
Expand Down
19 changes: 19 additions & 0 deletions examples/OpenSSLPrivateKeyEncryption/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"compact": "false",
"presets": [
[
"env",
{
"targets": {
"browsers": [ // Based on data from https://caniuse.com/#feat=cryptography
"Chrome >= 53",
"Firefox >= 47",
//"Edge >= 12", // Edge has incorrect or not complete WebCrypto API implementation (at least in v17)
"Safari >= 11",
"iOS >= 11.2"
]
}
}
]
]
}
147 changes: 147 additions & 0 deletions examples/OpenSSLPrivateKeyEncryption/OpenSSLPrivateKeyEncryption.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title>Parsing OpenSSL Encrypted Private Key</title>

<script type="application/javascript" src="../../node_modules/babel-polyfill/dist/polyfill.js"></script>
<script type="text/javascript" src="bundle.js"></script>

<style type="text/css">
body{background:#EFEFEF;font:normal 14px/16px Helvetica, Arial, sans-serif;}
.wrapper{
width:600px;
margin:50px auto;
padding:50px;
border:solid 2px #CCC;
border-radius:10px;
-webkit-border-radius:10px;
box-shadow:0 0 12px 3px #CDCDCD;
-webkit-box-shadow:0 0 12px 3px #CDCDCD;
background:#FFF;
}
label{
font:bold 16px/20px Helvetica, Arial, sans-serif;
margin:0 0 8px;
}
textarea{
width:500px;
border:solid 1px #999;
border-radius:5px;
-webkit-border-radius:5px;
height:340px;
font:normal 12px/15px monospace;
display:block;
margin:0 0 12px;
box-shadow:0 0 5px 5px #EFEFEF inset;
-webkit-box-shadow:0 0 5px 5px #EFEFEF inset;
padding:20px;
resize: none;
}
a{
display:inline-block;
padding:5px 15px;
background:#ACD0EC;
border:solid 1px #4C6181;
color:#000;
font:normal 14px/16px Helvetica, Arial, sans-serif;
}
a:hover{
background:#DAEBF8;
cursor:pointer;
}
.header-block {
margin-top:30px;
font:bold 16px/20px Helvetica, Arial, sans-serif;
}
.border-block{
border:solid 2px #999;
border-radius:5px;
-webkit-border-radius:5px;
margin:10px 0 0;
padding:20px 30px;
background:#F0F4FF;
}
.border-block h2{
margin:0 0 16px;
font:bold 22px/24px Helvetica, Arial, sans-serif;
}
.border-block p{
margin:0 0 12px;
}
.border-block p .type{
font-weight:bold;
display:inline-block;
width:176px;
}
.border-block .two-col{
overflow:hidden;
margin:0 0 16px;
}
.border-block .two-col .subject{
width:180px;
font-weight:bold;
margin:0 0 12px;
float:left;
}
.border-block .two-col #tsp-req-attributes{
margin:0;
padding:0;
float:left;
list-style:none;
}
.border-block .two-col #tsp-req-attributes li p{
margin:0;
}
.border-block .two-col #tsp-req-attributes li p span{
width:40px;
display:inline-block;
margin:0 0 5px;
}
.border-block .two-col #tsp-req-exten{
overflow:hidden;
padding:0 0 0 17px;
margin:0;
list-style-type:square;
}
table {
border:solid;
border-collapse:collapse;
border-color:black;
}
th {
text-align:center;
background: #ccc;
padding: 5px;
border: 1px solid black;
}
td {
padding: 5px;
border: 1px solid black;
}
</style>
</head>

<body>
<div class="wrapper">

<p class="header-block">Insert OpenSSL Encrypted Private Key</p>
<p>
<label for="password" style="float:left;">Password:</label>
<input id="password" type="text" />
</p>
<div id="input_div" class="border-block">
<label for="openssl_data" style="font-weight:bold;float:left;">PEM encoded Open SSL Private Key:</label>
<textarea id="openssl_data">&lt; Paste OpenSSL Encrypted Private Key here &gt;</textarea>
<a onclick="parseOpenSSLPrivateKey();">Parse</a>
</div>

<p class="header-block">Parsed OpenSSL Encrypted Private Key</p>
<div id="output_div" class="border-block">
<label for="pkijs_data" style="font-weight:bold;float:left;">Decrypted Open SSL Private Key:</label>
<textarea id="pkijs_data">&lt; Decrypted Open SSL Private Key would be here &gt;</textarea>
</div>
</div>
</body>
</html>
3 changes: 3 additions & 0 deletions examples/OpenSSLPrivateKeyEncryption/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Description

The example shows how to decrypt OpenSSL encrypted private keys using PKI.js
Loading