Skip to content

Commit

Permalink
Fixed error in import of crypto (#480) (#482)
Browse files Browse the repository at this point in the history
* Fixed error in import

* Updated release pipeline to run from different branches

* Updated pipeline

* Bump version

* Fixed error with broken crypto method
  • Loading branch information
AleksSavelev authored Oct 3, 2023
1 parent acd8484 commit a818a9a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ jobs:
GH_TOKEN: ${{secrets.GH_TOKEN}}
steps:
- uses: actions/checkout@v2
with:
ref: ${{ vars.BRANCH_NAME }}
- name: Add config details
run: |
git config --global user.name ${{secrets.NAME}}
Expand Down
2 changes: 2 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Change Log - PowerBI Visual Tools (pbiviz)

This page contains information about changes to the PowerBI Visual Tools (pbiviz).
## 5.1.1
* Updated crypto import to fix error in old Node versions

## 5.2.0
* Integrated PAC validation
Expand Down
14 changes: 9 additions & 5 deletions src/CertificateTools.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-case-declarations */
/*
* Power BI Visual CLI
*
Expand Down Expand Up @@ -30,7 +31,7 @@ import { exec as nodeExec } from 'child_process';
import fs from 'fs-extra';
import os from 'os';
import path from 'path';
import crypto, { webcrypto } from "crypto"
import crypto from "crypto"
import { getRootPath, readJsonFromRoot } from './utils.js';
import ConsoleWriter from './ConsoleWriter.js';

Expand Down Expand Up @@ -134,11 +135,8 @@ export async function createCertFile(config, open) {
}
break;
case "win32":
// eslint-disable-next-line no-case-declarations
let passphrase = "";
// for windows 7 and others
// 6.1 - Windows 7
// eslint-disable-next-line no-case-declarations
const osVersion = os.release().split(".");
if ((Number(osVersion[0]) === 6 && Number(osVersion[1]) === 1) || Number(osVersion[0]) < 6) {
await removeCertFiles(certPath, keyPath, pfxPath);
Expand All @@ -160,7 +158,13 @@ export async function createCertFile(config, open) {
}
break;
}
passphrase = (crypto.getRandomValues || <typeof crypto.getRandomValues>webcrypto.getRandomValues)(new Uint32Array(1))[0].toString().substring(2);
let randomValues: Uint32Array;
if(crypto.getRandomValues !== undefined){
randomValues = crypto.getRandomValues(new Uint32Array(1));
} else {
randomValues = crypto.webcrypto.getRandomValues(new Uint32Array(1));
}
const passphrase = randomValues[0].toString().substring(2);
config.server.passphrase = passphrase;
fs.writeFileSync(path.join(rootPath, confPath), JSON.stringify(config));
// for windows 8 / 8.1 / server 2012 R2 /
Expand Down

0 comments on commit a818a9a

Please sign in to comment.