Skip to content

Commit b521b7c

Browse files
ASN1.js V2 (ES2015/ES6)
1 parent f7181c2 commit b521b7c

File tree

9 files changed

+5616
-7259
lines changed

9 files changed

+5616
-7259
lines changed

.babelrc

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"compact": "false",
3+
"presets": ["es2015"]
4+
}

.gitignore

+2-156
Original file line numberDiff line numberDiff line change
@@ -1,156 +1,2 @@
1-
## Ignore Visual Studio temporary files, build results, and
2-
## files generated by popular Visual Studio add-ons.
3-
4-
# User-specific files
5-
*.suo
6-
*.user
7-
*.sln.docstates
8-
9-
# Build results
10-
11-
[Dd]ebug/
12-
[Rr]elease/
13-
x64/
14-
build/
15-
[Bb]in/
16-
[Oo]bj/
17-
18-
# Enable "build/" folder in the NuGet Packages folder since NuGet packages use it for MSBuild targets
19-
!packages/*/build/
20-
21-
# MSTest test Results
22-
[Tt]est[Rr]esult*/
23-
[Bb]uild[Ll]og.*
24-
25-
*_i.c
26-
*_p.c
27-
*.ilk
28-
*.meta
29-
*.obj
30-
*.pch
31-
*.pdb
32-
*.pgc
33-
*.pgd
34-
*.rsp
35-
*.sbr
36-
*.tlb
37-
*.tli
38-
*.tlh
39-
*.tmp
40-
*.tmp_proj
41-
*.log
42-
*.vspscc
43-
*.vssscc
44-
.builds
45-
*.pidb
46-
*.log
47-
*.scc
48-
49-
# Visual C++ cache files
50-
ipch/
51-
*.aps
52-
*.ncb
53-
*.opensdf
54-
*.sdf
55-
*.cachefile
56-
57-
# Visual Studio profiler
58-
*.psess
59-
*.vsp
60-
*.vspx
61-
62-
# Guidance Automation Toolkit
63-
*.gpState
64-
65-
# ReSharper is a .NET coding add-in
66-
_ReSharper*/
67-
*.[Rr]e[Ss]harper
68-
69-
# TeamCity is a build add-in
70-
_TeamCity*
71-
72-
# DotCover is a Code Coverage Tool
73-
*.dotCover
74-
75-
# NCrunch
76-
*.ncrunch*
77-
.*crunch*.local.xml
78-
79-
# Installshield output folder
80-
[Ee]xpress/
81-
82-
# DocProject is a documentation generator add-in
83-
DocProject/buildhelp/
84-
DocProject/Help/*.HxT
85-
DocProject/Help/*.HxC
86-
DocProject/Help/*.hhc
87-
DocProject/Help/*.hhk
88-
DocProject/Help/*.hhp
89-
DocProject/Help/Html2
90-
DocProject/Help/html
91-
92-
# Click-Once directory
93-
publish/
94-
95-
# Publish Web Output
96-
*.Publish.xml
97-
98-
# NuGet Packages Directory
99-
## TODO: If you have NuGet Package Restore enabled, uncomment the next line
100-
#packages/
101-
102-
# Windows Azure Build Output
103-
csx
104-
*.build.csdef
105-
106-
# Windows Store app package directory
107-
AppPackages/
108-
109-
# Others
110-
sql/
111-
*.Cache
112-
ClientBin/
113-
[Ss]tyle[Cc]op.*
114-
~$*
115-
*~
116-
*.dbmdl
117-
*.[Pp]ublish.xml
118-
*.pfx
119-
*.publishsettings
120-
121-
# RIA/Silverlight projects
122-
Generated_Code/
123-
124-
# Backup & report files from converting an old project file to a newer
125-
# Visual Studio version. Backup files are not needed, because we have git ;-)
126-
_UpgradeReport_Files/
127-
Backup*/
128-
UpgradeLog*.XML
129-
UpgradeLog*.htm
130-
131-
# SQL Server files
132-
App_Data/*.mdf
133-
App_Data/*.ldf
134-
135-
136-
#LightSwitch generated files
137-
GeneratedArtifacts/
138-
_Pvt_Extensions/
139-
ModelManifest.xml
140-
141-
# =========================
142-
# Windows detritus
143-
# =========================
144-
145-
# Windows image file caches
146-
Thumbs.db
147-
ehthumbs.db
148-
149-
# Folder config file
150-
Desktop.ini
151-
152-
# Recycle Bin used on file shares
153-
$RECYCLE.BIN/
154-
155-
# Mac desktop service store files
156-
.DS_Store
1+
node_modules
2+
build

.npmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
unsafe-perm = true

LICENSE

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Copyright (c) 2014, GMO GlobalSign
2-
Copyright (c) 2015, Peculiar Ventures
2+
Copyright (c) 2015-2017, Peculiar Ventures
33
All rights reserved.
44

5-
Author 2014-2015, Yury Strozhevsky
5+
Author 2014-2017, Yury Strozhevsky
66

77
Redistribution and use in source and binary forms, with or without modification,
88
are permitted provided that the following conditions are met:

README.md

+31-67
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,16 @@
77

88
Abstract Syntax Notation One (ASN.1) is a standard and notation that describes rules and structures for representing, encoding, transmitting, and decoding data in telecommunications and computer networking. [ASN1js][] is a pure JavaScript library implementing this standard. ASN.1 is the basis of all X.509 related data structures and numerous other protocols used on the web.
99

10+
## Important Information for ASN1.js V1 Users
11+
ASN1.js V2 (ES2015 version) is **incompactible** with ASN1.js V1 code.
12+
1013
## Introduction
1114

1215
[ASN1js][] is the first library for [BER][] encoding/decoding in Javascript designed for browser use. [BER][] is the basic encoding rules for [ASN.1][] that all others are based on, [DER][] is the encoding rules used by PKI applications - it is a subset of [BER][]. The [ASN1js][] library was tested against [freely available ASN.1:2008 test suite], with some limitations related to JavaScript language.
1316

1417
## Features of the library
1518

19+
* Based on latest features of JavaScipt language from ES2015 standard;
1620
* [ASN1js][] is a "base layer" for full-featured JS library [PKIjs][], which is using Web Cryptography API and has all classes, neccessary to work with PKI-related data;
1721
* Fully object-oriented library. Inhiritence is using everywhere inside the lib;
1822
* Working with HTML5 data objects (ArrayBuffer, Uint8Array etc.);
@@ -23,12 +27,12 @@ Abstract Syntax Notation One (ASN.1) is a standard and notation that describes r
2327
* Any sub-block may have unlimited length, as it described in ASN.1 standard (even "tag block");
2428
* Ability to work with ASN.1 string date types (intcluding all "international" strings like UniversalString, BMPString, UTF8String) by passing native JavaScript strings into constuctors. And vice versa - all initially parsed data of ASN.1 string types right after decoding automatically converts into native JavaScript strings;
2529
* Same with ASN.1 date-time types: for major types like UTCTime and GeneralizedTime there are automatic convertion between "JS date type - ASN.1 date-time type" + vice versa;
26-
* Same with ASN.1 OBJECT-IDENTIFIER (OID) data-type: you can initialize OID by JavaScript string and can get string representation via calling "oid.value_block.toString()";
30+
* Same with ASN.1 OBJECT-IDENTIFIER (OID) data-type: you can initialize OID by JavaScript string and can get string representation via calling "oid.valueBlock.toString()";
2731
* Working with "easy-to-understand" ASN.1 schemas (pre-defined or built by user);
2832
* Has special types to work with ASN.1 schemas:
29-
* ANY
30-
* CHOICE
31-
* REPEATED
33+
* Any
34+
* Choice
35+
* Repeated
3236
* User can name any block inside ASN.1 schema and easily get information by name;
3337
* Ability to parse internal data inside a primitively encoded data types and automatically validate it against special schema;
3438
* All types inside library are dynamic;
@@ -38,8 +42,8 @@ Abstract Syntax Notation One (ASN.1) is a standard and notation that describes r
3842

3943
```javascript
4044
// #region How to create new ASN. structures
41-
var sequence = new org.pkijs.asn1.SEQUENCE();
42-
sequence.value_block.value.push(new org.pkijs.asn1.INTEGER({ value: 1 }));
45+
var sequence = new asn1js.Sequence();
46+
sequence.valueBlock.value.push(new asn1js.Integer({ value: 1 }));
4347

4448
var sequence_buffer = sequence.toBER(false); // Encode current sequence to BER (in ArrayBuffer)
4549
var current_size = sequence_buffer.byteLength;
@@ -55,10 +59,10 @@ Abstract Syntax Notation One (ASN.1) is a standard and notation that describes r
5559
integer_view[6] = 0x01;
5660
integer_view[7] = 0x01;
5761

58-
sequence.value_block.value.push(new org.pkijs.asn1.INTEGER({
59-
is_hex_only: true,
60-
value_hex: integer_data
61-
})); // Put too long for decoding INTEGER value
62+
sequence.valueBlock.value.push(new asn1js.Integer({
63+
isHexOnly: true,
64+
valueHex: integer_data
65+
})); // Put too long for decoding Integer value
6266

6367
sequence_buffer = sequence.toBER(false);
6468
current_size = sequence_buffer.byteLength;
@@ -67,12 +71,12 @@ Abstract Syntax Notation One (ASN.1) is a standard and notation that describes r
6771

6872
```javascript
6973
// #region How to create new ASN.1 structures by calling constuctors with parameters
70-
var sequence2 = new org.pkijs.asn1.SEQUENCE({
74+
var sequence2 = new asn1js.Sequence({
7175
value: [
72-
new org.pkijs.asn1.INTEGER({ value: 1 }),
73-
new org.pkijs.asn1.INTEGER({
74-
is_hex_only: true,
75-
value_hex: integer_data
76+
new asn1js.Integer({ value: 1 }),
77+
new asn1js.Integer({
78+
isHexOnly: true,
79+
valueHex: integer_data
7680
}),
7781
]
7882
});
@@ -81,13 +85,13 @@ Abstract Syntax Notation One (ASN.1) is a standard and notation that describes r
8185

8286
```javascript
8387
// #region How to validate ASN.1 against pre-defined schema
84-
var asn1_schema = new org.pkijs.asn1.SEQUENCE({
88+
var asn1_schema = new asn1js.Sequence({
8589
name: "block1",
8690
value: [
87-
new org.pkijs.asn1.NULL({
91+
new asn1js.Null({
8892
name: "block2"
8993
}),
90-
new org.pkijs.asn1.INTEGER({
94+
new asn1js.Integer({
9195
name: "block3",
9296
optional: true // This block is absent inside data, but it's "optional". Hence verification against the schema will be passed.
9397
})
@@ -102,14 +106,14 @@ Abstract Syntax Notation One (ASN.1) is a standard and notation that describes r
102106

103107
```javascript
104108
// #region How to use "internal schemas" for primitevely encoded data types
105-
var primitive_octetstring = new org.pkijs.asn1.OCTETSTRING({ value_hex: encoded_sequence }); // Create a primitively encoded OCTETSTRING where internal data is an encoded SEQUENCE
109+
var primitive_octetstring = new asn1js.OctetString({ valueHex: encoded_sequence }); // Create a primitively encoded OctetString where internal data is an encoded Sequence
106110

107-
var asn1_schema_internal = new org.pkijs.asn1.OCTETSTRING({
111+
var asn1_schema_internal = new asn1js.OctetString({
108112
name: "outer_block",
109-
primitive_schema: new org.pkijs.asn1.SEQUENCE({
113+
primitiveSchema: new asn1js.Sequence({
110114
name: "block1",
111115
value: [
112-
new org.pkijs.asn1.NULL({
116+
new asn1js.Null({
113117
name: "block2"
114118
})
115119
]
@@ -118,8 +122,8 @@ Abstract Syntax Notation One (ASN.1) is a standard and notation that describes r
118122

119123
var variant6 = org.pkijs.compareSchema(primitive_octetstring, primitive_octetstring, asn1_schema_internal);
120124
var variant6_verified = variant4.verified;
121-
var variant6_block1_tag_num = variant6.result.block1.id_block.tag_number;
122-
var variant6_block2_tag_num = variant6.result.block2.id_block.tag_number;
125+
var variant6_block1_tag_num = variant6.result.block1.idBlock.tagNumber;
126+
var variant6_block2_tag_num = variant6.result.block2.idBlock.tagNumber;
123127
// #endregion
124128
```
125129

@@ -131,55 +135,15 @@ More examples could be found in "examples" directory or inside [PKIjs][] library
131135
* [Freely available ASN.1:2008 test suite](https://github.com/YuryStrozhevsky/ASN1-2008-free-test-suite) - the suite which can help you to validate (and better understand) any ASN.1 coder/decoder;
132136

133137
## Suitability
134-
At this time this library should be considered suitable for research and experimentation, futher code and security review is needed before utilization in a production application.
135-
136-
## How to use ASN1js and PKIjs with Node.js
137-
138-
**!!! WARNING !!! **
139-
**Currently there is no "polyfill" of WebCrypto in Node.js. Thus you will not be able to use signature / verification features of PKIjs in Node.js programs.**
140-
141-
In order to use [PKIjs][] you will also need [ASN1js][] plus [node.extend](https://www.npmjs.com/package/node.extend) package.
142-
```javascript
143-
var merge = require("node.extend");
144-
145-
var common = require("asn1js/org/pkijs/common");
146-
var _asn1js = require("asn1js");
147-
var _pkijs = require("pkijs");
148-
var _x509schema = require("pkijs/org/pkijs/x509_schema");
149-
150-
// #region Merging function/object declarations for ASN1js and PKIjs
151-
var asn1js = merge(true, _asn1js, common);
152-
153-
var x509schema = merge(true, _x509schema, asn1js);
154-
155-
var pkijs_1 = merge(true, _pkijs, asn1js);
156-
var pkijs = merge(true, pkijs_1, x509schema);
157-
// #endregion
158-
```
159-
160-
After that you will ba able to use ASN1js and PKIjs via common way:
161-
```javascript
162-
// #region Decode and parse X.509 cert
163-
var asn1 = pkijs.org.pkijs.fromBER(certBuffer);
164-
var cert;
165-
try
166-
{
167-
cert = new pkijs.org.pkijs.simpl.CERT({ schema: asn1.result });
168-
}
169-
catch(ex)
170-
{
171-
return;
172-
}
173-
// #endregion
174-
```
138+
There are several commercial products, enterprise solitions as well as open source project based on versions of ASN1js. You should, however, do your own code and security review before utilization in a production application before utilizing any open source library to ensure it will meet your needs.
175139

176140
## License
177141

178142
Copyright (c) 2014, [GMO GlobalSign](http://www.globalsign.com/)
179-
Copyright (c) 2015, [Peculiar Ventures](http://peculiarventures.com/)
143+
Copyright (c) 2015-2017, [Peculiar Ventures](http://peculiarventures.com/)
180144
All rights reserved.
181145

182-
Author 2014-2015, [Yury Strozhevsky](http://www.strozhevsky.com/).
146+
Author 2014-2017, [Yury Strozhevsky](http://www.strozhevsky.com/).
183147

184148
Redistribution and use in source and binary forms, with or without modification,
185149
are permitted provided that the following conditions are met:

0 commit comments

Comments
 (0)