Skip to content

Commit

Permalink
Merge pull request #10 from Microsoft/ianc/dev-cert-revisions
Browse files Browse the repository at this point in the history
  • Loading branch information
iclanton authored Sep 28, 2016
2 parents 3b8451c + 5ed9ff8 commit 8592369
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 44 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@microsoft/gulp-core-build-serve",
"version": "0.5.1",
"version": "0.5.2",
"description": "",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down
3 changes: 2 additions & 1 deletion src/CertificateStore.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as path from 'path';
import * as fs from 'fs';
import { homedir } from 'os';

const encoding: string = 'utf8';

Expand Down Expand Up @@ -72,7 +73,7 @@ export default class CertificateStore {
}

private _initialize(): void {
const unresolvedUserFolder: string = process.env[(process.platform === 'win32') ? 'USERPROFILE' : 'HOME'];
const unresolvedUserFolder: string = homedir();
this._userProfilePath = path.resolve(unresolvedUserFolder);
if (!fs.existsSync(this._userProfilePath)) {
throw new Error('Unable to determine the current user\'s home directory');
Expand Down
39 changes: 39 additions & 0 deletions src/NodeForgeExtensions.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
interface IAttr {
name: string;
value: string;
}

interface IForgeCertificate {
publicKey: any; // tslint:disable-line:no-any

validity: {
notBefore: Date;
notAfter: Date;
};

serialNumber: string;

setSubject(attrs: IAttr[]): void;

setIssuer(attrs: IAttr[]): void;

setExtensions(extensions: any[]): void; // tslint:disable-line:no-any

sign(privateKey: string, algorithm: IForgeSignatureAlgorithm): void; // tslint:disable-line:no-any
}

interface IForgeSignatureAlgorithm {
}

interface IForgeExtensions {
pki: {
createCertificate(): IForgeCertificate;
certificateToPem(certificate: IForgeCertificate): string;
};

md: {
sha256: {
create(): IForgeSignatureAlgorithm;
}
};
}
2 changes: 1 addition & 1 deletion src/TrustCertTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as gulp from 'gulp';
import { ensureCertificate, ICertificate } from './certificates';

/**
* This task gnerates and trusts a development certificate. The certificate is self-signed
* This task generates and trusts a development certificate. The certificate is self-signed
* and stored, along with its private key, in the user's home directory. On Windows, it's
* trusted as a root certification authority in the user certificate store. On macOS, it's
* trusted as a root cert in the keychain. On other platforms, the certificate is generated
Expand Down
45 changes: 4 additions & 41 deletions src/certificates.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/// <reference path="./NodeForgeExtensions.d.ts" />

import { GulpTask } from '@microsoft/gulp-core-build';
import * as forgeType from 'node-forge';
const forge: typeof forgeType & IForgeExtensions = require('node-forge');
Expand All @@ -21,46 +23,6 @@ export interface ICertificate {
pemKey: string;
}

interface IAttr {
name: string;
value: string;
}

interface IForgeCertificate {
publicKey: any; // tslint:disable-line:no-any

validity: {
notBefore: Date;
notAfter: Date;
};

serialNumber: string;

setSubject(attrs: IAttr[]): void;

setIssuer(attrs: IAttr[]): void;

setExtensions(extensions: any[]): void; // tslint:disable-line:no-any

sign(privateKey: string, algorithm: IForgeSignatureAlgorithm): void; // tslint:disable-line:no-any
}

interface IForgeSignatureAlgorithm {
}

interface IForgeExtensions {
pki: {
createCertificate(): IForgeCertificate;
certificateToPem(certificate: IForgeCertificate): string;
};

md: {
sha256: {
create(): IForgeSignatureAlgorithm;
}
};
}

function createDevelopmentCertificate(): ICertificate {
const keys: forgeType.pki.KeyPair = forge.pki.rsa.generateKeyPair(2048);
const certificate: IForgeCertificate = forge.pki.createCertificate();
Expand Down Expand Up @@ -186,7 +148,8 @@ function tryTrustCertificate(certificatePath: string, parentTask: GulpTask<{}>):
parentTask.log('Certificate trust cancelled.');
return false;
} else {
parentTask.logError('Certificate trust failed with an unknown error.');
parentTask.logError(`Certificate trust failed with an unknown error. Exit code: ${result.code}. ` +
`Error: ${result.stderr.join(' ')}`);
return false;
}
}
Expand Down

0 comments on commit 8592369

Please sign in to comment.