Skip to content

Commit

Permalink
Merge pull request #1 from Rodion93/develop
Browse files Browse the repository at this point in the history
Initial commit
  • Loading branch information
Rodion93 committed Nov 20, 2019
2 parents 6e1331f + ae53fb7 commit 37989ea
Show file tree
Hide file tree
Showing 14 changed files with 4,310 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"plugins": ["babel-plugin-rewire"]
}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,5 @@ typings/

# next.js build output
.next

/.vscode
2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/node_modules
/.vscode
Empty file added .prettierignore
Empty file.
14 changes: 14 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
language: node_js
node_js:
- 10
branches:
only:
- master

script: echo "Running tests against $(node -v)..."

jobs:
include:
- stage: Produce Coverage
node_js: node
script: jest --coverage && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2019 Rodion93
Copyright (c) 2019 Rodion Horbulenko

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
135 changes: 135 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
win-cert
======

[![Build Status](https://travis-ci.org/Rodion93/win-cert.svg?branch=master)](https://travis-ci.org/Rodion93/win-cert) [![Coverage Status](https://coveralls.io/repos/github/Rodion93/win-cert/badge.svg?branch=master)](https://coveralls.io/github/Rodion93/win-cert?branch=master)

win-cert - Library for obtaining certificates from the Windows certificate store.

ATTENTION - If you want to get one certificate, your certificate must be marked as exported
and must be imported properly (the key must be stored in the right place), otherwise the method
returns a certificate with an empty private key.

Init
===========

```bash
npm install win-cert
```
or
```bash
yarn add win-cert
```

API
===========

### getCertificate

Returns certificate and private key in PEM format.
Options are required;

```javascript
const winCert = require('win-cert');

...

const options = {
storeName: 'My',
storeLocation: 'CurrentUser',
thumbprint: '098d3.....'
};

const certAndKey = await winCert.getCertificate(options);

certAndKey.cert;
certAndKey.key;

```

### getAllCertificates

Returns all certificates as objects. Options are not required.

The returned object `certs` is a object like this:

```json
{
"subject": "CN=hello.com, O=Internet Widgits Pty Ltd, S=Some-State, C=AU",
"issuer": "foo bar",
"thumbprint": "...",
"pem": "-----BEGIN CERTIFICATE-----\nMIID9DCCAtygAwIBAgIJANWBEUdUZOlPMA0GCSqGSIb3DQEBBQUAMFkxCzAJBgNV..."
}
```

```javascript
const winCert = require('win-cert');

...

const options = {
storeName: 'My',
storeLocation: 'CurrentUser'
};

const certificates = await winCert.getAllCertificates(options);

certificates.forEach(cert => {
console.log(cert);
});

```

Example application
===========

```javascript
const winCert = require('win-cert');
const express = require('express');
const https = require('https');

const main = async () => {
const certAndKey = await winCert.getCertificate({
storeName: 'Root',
storeLocation: 'LocalMachine',
thumbprint: 'Your thumbprint'
});

const options = {
cert: certAndKey.cert,
key: certAndKey.key,
ca: certAndKey.cert,
requestCert: true,
rejectUnauthorized: false
};

const app = express();

https
.createServer(options, app)
.listen(44331, () => console.log('Server started listening'));
};

main();
```

or

```javascript
const winCert = require('win-cert');

const main = async () => {
const allCerts = await winCert.getAllCertificates({
storeName: 'Root',
storeLocation: 'CurrentUser'
});

allCerts.forEach(cert => console.log(cert));
};

main();
```

License
=======

MIT
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';

module.exports = require('./src/winCert');
51 changes: 51 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"name": "win-cert",
"version": "0.1.0",
"description": "Library for obtaining certificates from the Windows certificate store",
"main": "index.js",
"license": "MIT",
"keywords": [
"win",
"certificate",
"getCertificate",
"win store",
"X509",
"pem"
],
"licenses": [
{
"type": "MIT",
"url": "http://www.opensource.org/licenses/MIT"
}
],
"author": {
"name": "Rodion Horbulenko"
},
"repository": {
"type": "git",
"url": "https://github.com/Rodion93/win-cert.git"
},
"bugs": {
"url": "https://github.com/Rodion93/win-cert/issues"
},
"scripts": {
"test": "jest"
},
"engines": {
"node": ">= 10.17.0"
},
"files": [
"README.md",
"index.js",
"LICENSE"
],
"dependencies": {
"edge-js": "^13.0.1"
},
"devDependencies": {
"babel-jest": "^24.9.0",
"babel-plugin-rewire": "^1.2.0",
"coveralls": "^3.0.7",
"jest": "^24.9.0"
}
}
Loading

0 comments on commit 37989ea

Please sign in to comment.