diff --git a/angular.json b/angular.json index fb6dca3f..0715f12b 100644 --- a/angular.json +++ b/angular.json @@ -1720,6 +1720,39 @@ } } } + }, + "ucap-webmessenger-daesang": { + "projectType": "library", + "root": "projects/ucap-webmessenger-daesang", + "sourceRoot": "projects/ucap-webmessenger-daesang/src", + "prefix": "ucap-daesang", + "architect": { + "build": { + "builder": "@angular-devkit/build-ng-packagr:build", + "options": { + "tsConfig": "projects/ucap-webmessenger-daesang/tsconfig.lib.json", + "project": "projects/ucap-webmessenger-daesang/ng-package.json" + } + }, + "test": { + "builder": "@angular-devkit/build-angular:karma", + "options": { + "main": "projects/ucap-webmessenger-daesang/src/test.ts", + "tsConfig": "projects/ucap-webmessenger-daesang/tsconfig.spec.json", + "karmaConfig": "projects/ucap-webmessenger-daesang/karma.conf.js" + } + }, + "lint": { + "builder": "@angular-devkit/build-angular:tslint", + "options": { + "tsConfig": [ + "projects/ucap-webmessenger-daesang/tsconfig.lib.json", + "projects/ucap-webmessenger-daesang/tsconfig.spec.json" + ], + "exclude": ["**/node_modules/**"] + } + } + } } }, "defaultProject": "ucap-webmessenger-app" diff --git a/electron-projects/ucap-webmessenger-electron/src/index.ts b/electron-projects/ucap-webmessenger-electron/src/index.ts index e84ff168..0fb16520 100644 --- a/electron-projects/ucap-webmessenger-electron/src/index.ts +++ b/electron-projects/ucap-webmessenger-electron/src/index.ts @@ -287,32 +287,32 @@ ipcMain.on(UpdaterChannel.Check, (event: IpcMainEvent, ...args: any[]) => { ipcMain.on( UpdaterChannel.StartCheckInstant, (event: IpcMainEvent, ...args: any[]) => { - const config = args[0] as UpdateCheckConfig; - if (!!rendererUpdater) { - rendererUpdater.stopCheck(); - rendererUpdater = null; - } - rendererUpdater = new RendererUpdater(appWindow.browserWindow, config); // default 10min - rendererUpdater.startCheck(); + // const config = args[0] as UpdateCheckConfig; + // if (!!rendererUpdater) { + // rendererUpdater.stopCheck(); + // rendererUpdater = null; + // } + // rendererUpdater = new RendererUpdater(appWindow.browserWindow, config); // default 10min + // rendererUpdater.startCheck(); } ); ipcMain.on( UpdaterChannel.StopCheckInstant, (event: IpcMainEvent, ...args: any[]) => { - if (!!rendererUpdater) { - rendererUpdater.stopCheck(); - rendererUpdater = null; - } + // if (!!rendererUpdater) { + // rendererUpdater.stopCheck(); + // rendererUpdater = null; + // } } ); ipcMain.on( UpdaterChannel.ApplyInstant, (event: IpcMainEvent, ...args: any[]) => { - if (!!rendererUpdater) { - rendererUpdater.apply(); - } + // if (!!rendererUpdater) { + // rendererUpdater.apply(); + // } } ); diff --git a/projects/ucap-webmessenger-app/src/app/app.module.ts b/projects/ucap-webmessenger-app/src/app/app.module.ts index 6e3a5d86..1b3d1573 100644 --- a/projects/ucap-webmessenger-app/src/app/app.module.ts +++ b/projects/ucap-webmessenger-app/src/app/app.module.ts @@ -33,6 +33,8 @@ import { UCapServiceProtocolModule } from '@ucap-webmessenger/protocol-service'; import { UCapStatusProtocolModule } from '@ucap-webmessenger/protocol-status'; import { UCapSyncProtocolModule } from '@ucap-webmessenger/protocol-sync'; +import { UCapDaesangModule } from '@ucap-webmessenger/daesang'; + import { LoggerModule, NgxLoggerLevel } from 'ngx-logger'; import { AppProviderModule } from './app-provider.module'; @@ -79,6 +81,8 @@ import { environment } from '../environments/environment'; UCapStatusProtocolModule.forRoot(), UCapSyncProtocolModule.forRoot(), + UCapDaesangModule.forRoot(), + UCapUiModule.forRoot(), UCapUiAccountModule.forRoot(), diff --git a/projects/ucap-webmessenger-app/src/app/services/authentication.service.ts b/projects/ucap-webmessenger-app/src/app/services/authentication.service.ts index 65e38deb..3b2823ce 100644 --- a/projects/ucap-webmessenger-app/src/app/services/authentication.service.ts +++ b/projects/ucap-webmessenger-app/src/app/services/authentication.service.ts @@ -9,6 +9,7 @@ import { LoginInfo, KEY_LOGIN_INFO } from '../types'; import { KEY_VER_INFO } from '@app/types/ver-info.type'; import { KEY_LOGIN_RES_INFO } from '@app/types/login-res-info.type'; import { PasswordUtil } from '@ucap-webmessenger/pi'; +import { DaesangCipherService } from '@ucap-webmessenger/daesang'; @Injectable({ providedIn: 'root' @@ -18,7 +19,8 @@ export class AppAuthenticationService { constructor( private sessionStorageService: SessionStorageService, - private localStorageService: LocalStorageService + private localStorageService: LocalStorageService, + private daesangCipherService: DaesangCipherService ) {} authenticated(): boolean { @@ -32,7 +34,12 @@ export class AppAuthenticationService { this.sessionStorageService.set(KEY_LOGIN_INFO, { ...loginInfo, initPw: loginInfo.loginId === loginInfo.loginPw, - loginPw: PasswordUtil.encrypt(loginInfo.loginPw) + // loginPw: PasswordUtil.encrypt(loginInfo.loginPw) + loginPw: this.daesangCipherService.encrypt( + 'DaesangSSOProject', + loginInfo.loginPw, + 'N' + ) }); if (rememberMe) { diff --git a/projects/ucap-webmessenger-daesang/README.md b/projects/ucap-webmessenger-daesang/README.md new file mode 100644 index 00000000..de5e6841 --- /dev/null +++ b/projects/ucap-webmessenger-daesang/README.md @@ -0,0 +1,24 @@ +# UcapWebmessengerDaesang + +This library was generated with [Angular CLI](https://github.com/angular/angular-cli) version 8.2.11. + +## Code scaffolding + +Run `ng generate component component-name --project ucap-webmessenger-daesang` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module --project ucap-webmessenger-daesang`. +> Note: Don't forget to add `--project ucap-webmessenger-daesang` or else it will be added to the default project in your `angular.json` file. + +## Build + +Run `ng build ucap-webmessenger-daesang` to build the project. The build artifacts will be stored in the `dist/` directory. + +## Publishing + +After building your library with `ng build ucap-webmessenger-daesang`, go to the dist folder `cd dist/ucap-webmessenger-daesang` and run `npm publish`. + +## Running unit tests + +Run `ng test ucap-webmessenger-daesang` to execute the unit tests via [Karma](https://karma-runner.github.io). + +## Further help + +To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI README](https://github.com/angular/angular-cli/blob/master/README.md). diff --git a/projects/ucap-webmessenger-daesang/karma.conf.js b/projects/ucap-webmessenger-daesang/karma.conf.js new file mode 100644 index 00000000..dcf20eca --- /dev/null +++ b/projects/ucap-webmessenger-daesang/karma.conf.js @@ -0,0 +1,32 @@ +// Karma configuration file, see link for more information +// https://karma-runner.github.io/1.0/config/configuration-file.html + +module.exports = function (config) { + config.set({ + basePath: '', + frameworks: ['jasmine', '@angular-devkit/build-angular'], + plugins: [ + require('karma-jasmine'), + require('karma-chrome-launcher'), + require('karma-jasmine-html-reporter'), + require('karma-coverage-istanbul-reporter'), + require('@angular-devkit/build-angular/plugins/karma') + ], + client: { + clearContext: false // leave Jasmine Spec Runner output visible in browser + }, + coverageIstanbulReporter: { + dir: require('path').join(__dirname, '../../coverage/ucap-webmessenger-daesang'), + reports: ['html', 'lcovonly', 'text-summary'], + fixWebpackSourcePaths: true + }, + reporters: ['progress', 'kjhtml'], + port: 9876, + colors: true, + logLevel: config.LOG_INFO, + autoWatch: true, + browsers: ['Chrome'], + singleRun: false, + restartOnFileChange: true + }); +}; diff --git a/projects/ucap-webmessenger-daesang/ng-package.json b/projects/ucap-webmessenger-daesang/ng-package.json new file mode 100644 index 00000000..351b484e --- /dev/null +++ b/projects/ucap-webmessenger-daesang/ng-package.json @@ -0,0 +1,7 @@ +{ + "$schema": "../../node_modules/ng-packagr/ng-package.schema.json", + "dest": "../../dist/ucap-webmessenger-daesang", + "lib": { + "entryFile": "src/public-api.ts" + } +} \ No newline at end of file diff --git a/projects/ucap-webmessenger-daesang/package.json b/projects/ucap-webmessenger-daesang/package.json new file mode 100644 index 00000000..c202d77c --- /dev/null +++ b/projects/ucap-webmessenger-daesang/package.json @@ -0,0 +1,8 @@ +{ + "name": "@ucap-webmessenger/daesang", + "version": "0.0.1", + "peerDependencies": { + "@angular/common": "^8.2.11", + "@angular/core": "^8.2.11" + } +} diff --git a/projects/ucap-webmessenger-daesang/src/lib/models/CipherKeyDTD.ts b/projects/ucap-webmessenger-daesang/src/lib/models/CipherKeyDTD.ts new file mode 100644 index 00000000..556236dd --- /dev/null +++ b/projects/ucap-webmessenger-daesang/src/lib/models/CipherKeyDTD.ts @@ -0,0 +1,4 @@ +export interface CipherKeyDTD { + key: Uint8Array; + iv: Uint8Array; +} diff --git a/projects/ucap-webmessenger-daesang/src/lib/services/daesang-cipher.service.spec.ts b/projects/ucap-webmessenger-daesang/src/lib/services/daesang-cipher.service.spec.ts new file mode 100644 index 00000000..9fa31fb6 --- /dev/null +++ b/projects/ucap-webmessenger-daesang/src/lib/services/daesang-cipher.service.spec.ts @@ -0,0 +1,12 @@ +import { TestBed } from '@angular/core/testing'; + +import { DaesangCipherService } from './daesang-cipher.service'; + +describe('DaesangCipherService', () => { + beforeEach(() => TestBed.configureTestingModule({})); + + it('should be created', () => { + const service: DaesangCipherService = TestBed.get(DaesangCipherService); + expect(service).toBeTruthy(); + }); +}); diff --git a/projects/ucap-webmessenger-daesang/src/lib/services/daesang-cipher.service.ts b/projects/ucap-webmessenger-daesang/src/lib/services/daesang-cipher.service.ts new file mode 100644 index 00000000..8ba8a014 --- /dev/null +++ b/projects/ucap-webmessenger-daesang/src/lib/services/daesang-cipher.service.ts @@ -0,0 +1,37 @@ +import { Injectable } from '@angular/core'; + +import crypto from 'crypto'; + +import { CipherUtil } from '../utils/CipherUtil'; + +@Injectable({ + providedIn: 'root' +}) +export class DaesangCipherService { + constructor() {} + + encrypt(pvUserKey: string, pvSource: string, isBase64: string): string { + const cipherKeyDTD = CipherUtil.makeCipherKey('AES', pvUserKey); + + const cipher = crypto.createCipheriv( + 'aes-128-cbc', + cipherKeyDTD.key, + cipherKeyDTD.iv + ); + cipher.setAutoPadding(true); + + let outputEncoding: 'base64' | 'hex'; + + if ('Y' === isBase64) { + outputEncoding = 'base64'; + } else { + outputEncoding = 'hex'; + } + + const cipherChunks = []; + cipherChunks.push(cipher.update(pvSource, 'utf8', outputEncoding)); + cipherChunks.push(cipher.final(outputEncoding)); + + return cipherChunks.join(''); + } +} diff --git a/projects/ucap-webmessenger-daesang/src/lib/ucap-daesang.module.ts b/projects/ucap-webmessenger-daesang/src/lib/ucap-daesang.module.ts new file mode 100644 index 00000000..d0c57055 --- /dev/null +++ b/projects/ucap-webmessenger-daesang/src/lib/ucap-daesang.module.ts @@ -0,0 +1,19 @@ +import { NgModule, ModuleWithProviders } from '@angular/core'; + +import { DaesangCipherService } from './services/daesang-cipher.service'; + +const SERVICES = [DaesangCipherService]; + +@NgModule({ + declarations: [], + imports: [], + exports: [] +}) +export class UCapDaesangModule { + public static forRoot(): ModuleWithProviders { + return { + ngModule: UCapDaesangModule, + providers: [...SERVICES] + }; + } +} diff --git a/projects/ucap-webmessenger-daesang/src/lib/utils/ByteUtils.ts b/projects/ucap-webmessenger-daesang/src/lib/utils/ByteUtils.ts new file mode 100644 index 00000000..f501ce1c --- /dev/null +++ b/projects/ucap-webmessenger-daesang/src/lib/utils/ByteUtils.ts @@ -0,0 +1,32 @@ +export class ByteUtils { + static toBytesFromHexString(hex: string): Uint8Array { + if (!hex) { + return new Uint8Array(); + } + return new Uint8Array(hex.match(/.{1,2}/g).map(byte => parseInt(byte, 16))); + } + + static toHexString(bytes: Uint8Array): string { + if (!bytes) { + return ''; + } + return bytes.reduce( + (str, byte) => str + byte.toString(16).padStart(2, '0'), + '' + ); + } + + static toBytesFromString(s: string): Uint8Array { + if (!s) { + return new Uint8Array(); + } + return new TextEncoder().encode(s); + } + + static toStringFromBytes(bytes: Uint8Array): string { + if (!bytes) { + return ''; + } + return new TextDecoder('utf-8').decode(bytes); + } +} diff --git a/projects/ucap-webmessenger-daesang/src/lib/utils/CipherUtil.ts b/projects/ucap-webmessenger-daesang/src/lib/utils/CipherUtil.ts new file mode 100644 index 00000000..df08fbd6 --- /dev/null +++ b/projects/ucap-webmessenger-daesang/src/lib/utils/CipherUtil.ts @@ -0,0 +1,41 @@ +import CryptoJS from 'crypto-js'; + +import { ByteUtils } from './ByteUtils'; +import { CipherKeyDTD } from '../models/CipherKeyDTD'; + +export class CipherUtil { + static makeCipherKey(pvAlgorithm: string, pvUserKey: string): CipherKeyDTD { + let keyBytes: Uint8Array; + let ivBytes: Uint8Array; + + if ( + !pvUserKey || + '' === pvUserKey.trim() || + 'eMateOnepass_SSO' === pvUserKey + ) { + keyBytes = ByteUtils.toBytesFromString('eMateOnepass_SSO'); + ivBytes = ByteUtils.toBytesFromString('eMateOnepass_SSO'); + } else if ( + '201007GYCSSOPROJ' === pvUserKey || + '201005KICSSOPROJ' === pvUserKey + ) { + keyBytes = ByteUtils.toBytesFromString(pvUserKey); + ivBytes = ByteUtils.toBytesFromString(pvUserKey); + } else { + const bytes = ByteUtils.toBytesFromHexString( + CryptoJS.SHA1(pvUserKey).toString() + ); + + keyBytes = bytes.slice(0, 16); + + ivBytes = ByteUtils.toBytesFromHexString( + CryptoJS.SHA1(ByteUtils.toHexString(bytes.slice(16, 20))).toString() + ).slice(0, 16); + } + + return { + key: keyBytes, + iv: ivBytes + } as CipherKeyDTD; + } +} diff --git a/projects/ucap-webmessenger-daesang/src/public-api.ts b/projects/ucap-webmessenger-daesang/src/public-api.ts new file mode 100644 index 00000000..a59808f2 --- /dev/null +++ b/projects/ucap-webmessenger-daesang/src/public-api.ts @@ -0,0 +1,7 @@ +/* + * Public API Surface of ucap-webmessenger-daesang + */ + +export * from './lib/services/daesang-cipher.service'; + +export * from './lib/ucap-daesang.module'; diff --git a/projects/ucap-webmessenger-daesang/src/test.ts b/projects/ucap-webmessenger-daesang/src/test.ts new file mode 100644 index 00000000..978c64fb --- /dev/null +++ b/projects/ucap-webmessenger-daesang/src/test.ts @@ -0,0 +1,21 @@ +// This file is required by karma.conf.js and loads recursively all the .spec and framework files + +import 'zone.js/dist/zone'; +import 'zone.js/dist/zone-testing'; +import { getTestBed } from '@angular/core/testing'; +import { + BrowserDynamicTestingModule, + platformBrowserDynamicTesting +} from '@angular/platform-browser-dynamic/testing'; + +declare const require: any; + +// First, initialize the Angular testing environment. +getTestBed().initTestEnvironment( + BrowserDynamicTestingModule, + platformBrowserDynamicTesting() +); +// Then we find all the tests. +const context = require.context('./', true, /\.spec\.ts$/); +// And load the modules. +context.keys().map(context); diff --git a/projects/ucap-webmessenger-daesang/tsconfig.lib.json b/projects/ucap-webmessenger-daesang/tsconfig.lib.json new file mode 100644 index 00000000..bd23948e --- /dev/null +++ b/projects/ucap-webmessenger-daesang/tsconfig.lib.json @@ -0,0 +1,26 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "outDir": "../../out-tsc/lib", + "target": "es2015", + "declaration": true, + "inlineSources": true, + "types": [], + "lib": [ + "dom", + "es2018" + ] + }, + "angularCompilerOptions": { + "annotateForClosureCompiler": true, + "skipTemplateCodegen": true, + "strictMetadataEmit": true, + "fullTemplateTypeCheck": true, + "strictInjectionParameters": true, + "enableResourceInlining": true + }, + "exclude": [ + "src/test.ts", + "**/*.spec.ts" + ] +} diff --git a/projects/ucap-webmessenger-daesang/tsconfig.spec.json b/projects/ucap-webmessenger-daesang/tsconfig.spec.json new file mode 100644 index 00000000..16da33db --- /dev/null +++ b/projects/ucap-webmessenger-daesang/tsconfig.spec.json @@ -0,0 +1,17 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "outDir": "../../out-tsc/spec", + "types": [ + "jasmine", + "node" + ] + }, + "files": [ + "src/test.ts" + ], + "include": [ + "**/*.spec.ts", + "**/*.d.ts" + ] +} diff --git a/projects/ucap-webmessenger-daesang/tslint.json b/projects/ucap-webmessenger-daesang/tslint.json new file mode 100644 index 00000000..77e2b18a --- /dev/null +++ b/projects/ucap-webmessenger-daesang/tslint.json @@ -0,0 +1,17 @@ +{ + "extends": "../../tslint.json", + "rules": { + "directive-selector": [ + true, + "attribute", + "ucapDaesang", + "camelCase" + ], + "component-selector": [ + true, + "element", + "ucap-daesang", + "kebab-case" + ] + } +} diff --git a/tsconfig.json b/tsconfig.json index 2b65e11b..c4514639 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -146,6 +146,9 @@ ], "@ucap-webmessenger/electron": [ "electron-projects/ucap-webmessenger-electron/src/public-api" + ], + "@ucap-webmessenger/daesang": [ + "projects/ucap-webmessenger-daesang/src/public-api" ] } },