@@ -18,9 +18,9 @@ export interface CodeSigningInfo {
1818 keychainName ?: string | null
1919}
2020
21- export async function downloadCertificate ( urlOrBase64 : string , tmpDir : TmpDir ) : Promise < string > {
21+ export async function downloadCertificate ( urlOrBase64 : string , tmpDir : TmpDir , currentDir : string ) : Promise < string > {
2222 let file : string | null = null
23- if ( ( urlOrBase64 . length > 3 && urlOrBase64 [ 1 ] === ":" ) || urlOrBase64 . startsWith ( "/" ) ) {
23+ if ( ( urlOrBase64 . length > 3 && urlOrBase64 [ 1 ] === ":" ) || urlOrBase64 . startsWith ( "/" ) || urlOrBase64 . startsWith ( "." ) ) {
2424 file = urlOrBase64
2525 }
2626 else if ( urlOrBase64 . startsWith ( "file://" ) ) {
@@ -30,16 +30,23 @@ export async function downloadCertificate(urlOrBase64: string, tmpDir: TmpDir):
3030 file = path . join ( homedir ( ) , urlOrBase64 . substring ( "~/" . length ) )
3131 }
3232 else {
33- const tempFile = await tmpDir . getTempFile ( ".p12" )
34- if ( urlOrBase64 . startsWith ( "https://" ) ) {
35- await download ( urlOrBase64 , tempFile )
33+ const isUrl = urlOrBase64 . startsWith ( "https://" )
34+ if ( isUrl || urlOrBase64 . length > 4096 || urlOrBase64 . endsWith ( "=" ) ) {
35+ const tempFile = await tmpDir . getTempFile ( ".p12" )
36+ if ( isUrl ) {
37+ await download ( urlOrBase64 , tempFile )
38+ }
39+ else {
40+ await outputFile ( tempFile , new Buffer ( urlOrBase64 , "base64" ) )
41+ }
42+ return tempFile
3643 }
3744 else {
38- await outputFile ( tempFile , new Buffer ( urlOrBase64 , "base64" ) )
45+ file = urlOrBase64
3946 }
40- return tempFile
4147 }
4248
49+ file = path . resolve ( currentDir , file . trim ( ) )
4350 const stat = await statOrNull ( file )
4451 if ( stat == null ) {
4552 throw new Error ( `${ file } doesn't exist` )
@@ -80,7 +87,16 @@ async function createCustomCertKeychain() {
8087 }
8188}
8289
83- export async function createKeychain ( tmpDir : TmpDir , cscLink : string , cscKeyPassword : string , cscILink ?: string | null , cscIKeyPassword ?: string | null ) : Promise < CodeSigningInfo > {
90+ export interface CreateKeychainOptions {
91+ tmpDir : TmpDir
92+ cscLink : string
93+ cscKeyPassword : string
94+ cscILink ?: string | null
95+ cscIKeyPassword ?: string | null
96+ currentDir : string
97+ }
98+
99+ export async function createKeychain ( { tmpDir, cscLink, cscKeyPassword, cscILink, cscIKeyPassword, currentDir} : CreateKeychainOptions ) : Promise < CodeSigningInfo > {
84100 if ( bundledCertKeychainAdded == null ) {
85101 bundledCertKeychainAdded = createCustomCertKeychain ( )
86102 }
@@ -96,7 +112,7 @@ export async function createKeychain(tmpDir: TmpDir, cscLink: string, cscKeyPass
96112 const certPaths = new Array ( certLinks . length )
97113 const keychainPassword = randomBytes ( 8 ) . toString ( "hex" )
98114 return await executeFinally ( BluebirdPromise . all ( [
99- BluebirdPromise . map ( certLinks , ( link , i ) => downloadCertificate ( link , tmpDir ) . then ( it => certPaths [ i ] = it ) ) ,
115+ BluebirdPromise . map ( certLinks , ( link , i ) => downloadCertificate ( link , tmpDir , currentDir ) . then ( it => certPaths [ i ] = it ) ) ,
100116 BluebirdPromise . mapSeries ( [
101117 [ "create-keychain" , "-p" , keychainPassword , keychainName ] ,
102118 [ "unlock-keychain" , "-p" , keychainPassword , keychainName ] ,
0 commit comments