Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AG-47_more-sites #70

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions DEVELOPERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,9 @@ API dbridge_js funguje nasledovne:
- `img` - zdrojové obrázky na distribuciu (do store-u)
- `options` - funkcionalita nastaveni ktora je zdielana medzi roznymi entrypointami
- `static` - staticke subory vkladane do buildu (obrazky, podstranky)


## Stranky na ktorych treba otestovat ci funguju spravne

- https://schranka.slovensko.sk/FormConstructor/Default.aspx
- https://portal.minv.sk/wps/myportal/domov/co2/podania/pobyt/
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Alebo si viete stiahnuť zip z podstránky [Releases](https://github.com/slovens

- Slovensko.sk (UPVS - Ústredný portál verejnej správy) https://www.slovensko.sk/, https://schranka.slovensko.sk
- Finančná správa (PFS - Portál finančnej správy) https://www.financnasprava.sk/, https://pfseform.financnasprava.sk/
- Colné vyhlásenie pre zásielku s nízkou hodnotou https://www.ecm.financnasprava.sk/Formular/Dovozne-CV-tovar-s-nizkou-hodnotou

Ak máte záujem o podporu na iných weboch vytvorte [novú issue](https://github.com/slovensko-digital/autogram-extension/issues/new)

Expand Down
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ export const enabledUrls = [
"https://schranka.slovensko.sk/*",
"https://pfseform.financnasprava.sk/*",
"https://www.financnasprava.sk/*",
"https://portal.minv.sk/*",
...(process.env.NODE_ENV !== "production" ? ["http://localhost:3000/*"] : []),
];
1 change: 1 addition & 0 deletions src/dbridge_js/ditecx/autogram-implementation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ export class DBridgeAutogramImpl {
this.signerIdentificationListeners = [];
this.signatureIndex++;

console.log(callback);
callback.onSuccess(
// TODO skontrolovat ci sa to niekedy moze pouzivat
decodeBase64
Expand Down
43 changes: 43 additions & 0 deletions src/dbridge_js/ditecx/ditecx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const ditecX = {
title: "",
},
},
versions: {},
utils: {
ERROR_CANCELLED: 1,
ERROR_GENERAL: -200,
Expand All @@ -25,7 +26,49 @@ export const ditecX = {
console.log("isDitecError", error);
return true;
},
extendClass: /* TODO */ function (child, parent) {
console.log("extendClass", child, parent);
const F = function () {};
F.prototype = parent.prototype;
child.prototype = new F();
child._superClass = parent.prototype;
child.prototype.constructor = child;
for (const member in child) {
child.prototype[member] = child[member];
}
for (const member in parent) {
child[member] = parent[member];
child.prototype[member] = parent[member];
}
},
ChainedCallback: /* TODO */ function (callback) {},
},
dSigXadesJs: new DSigXadesAdapter(implementation),
dSigXadesBpJs: new DSigXadesBpAdapter(implementation),

/* TODO */
dSigXadesExtenderJs: new DSigXadesAdapter(implementation),

dCommon: {
/* TODO */
},
detectSupportedPlatforms: function () {
/* TODO */
},
AbstractLauncherWrapper: function () {
/* TODO */
},
DSigXadesDLauncherJava: function () {
/* TODO */
},
DSigXadesExtenderDLauncherJava: function () {
/* TODO */
},
AbstractJsCore: function () {
/* TODO */
},
AbstractDotNetWrapper: function () {
/* TODO */
},
dLauncher: {},
};
15 changes: 14 additions & 1 deletion src/dbridge_js/ditecx/dsig-base-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class DSigAdapter {
stub(name: string, ...rest: unknown[]): void {
this.log(name, ...rest);
// alert(`Stubbed ${this.constructor.name} method: \n\n${name}`);
console.warn(`Stubbed ${this.constructor.name} method: \n\n${name}`)
console.warn(`Stubbed ${this.constructor.name} method: \n\n${name}`);
}

checkPDFACompliance(sourcePdfBase64, password, reqLevel, callback) {
Expand All @@ -79,4 +79,17 @@ export class DSigAdapter {
this.log("getSignerIdentification", arguments);
this.__implementation.getSignerIdentification(callback);
}

detectSupportedPlatforms(platforms, callback) {
console.log({ platforms });

// callback.onSuccess(["autogram"]);
callback.onSuccess(["java"]);
}

deploy(config: { platforms: any }, callback) {
console.log("deploy on platforms", config);
// callback.onSuccess(instance);
callback.onSuccess();
}
}
30 changes: 25 additions & 5 deletions src/dbridge_js/ditecx/dsig-xades-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,22 @@ export class DSigXadesAdapter extends DSigAdapter {
dataEnvelopeDescr,
callback
) {
this.stub("sign20", arguments);
// this.stub("sign20", arguments);
this.log("sign20", arguments, {
signatureId,
digestAlgUri,
signaturePolicyIdentifier,
dataEnvelopeId,
dataEnvelopeURI,
dataEnvelopeDescr,
});

this.__implementation.sign(
signatureId,
digestAlgUri,
signaturePolicyIdentifier,
callback
);
}

// ---------------
Expand All @@ -160,19 +175,24 @@ export class DSigXadesAdapter extends DSigAdapter {
setCertificateFilter(filterID, callback) {
this.stub("", arguments);
}

getSignedXmlWithEnvelope(callback) {
this.log("getSignedXmlWithEnvelope", arguments);
this.__implementation.getSignature(
{
container: null,
containerXmlns: null,
level: "XAdES_BASELINE_B",
packaging: "ENVELOPING",
// container: null,
// containerXmlns: null,
// level: "XAdES_BASELINE_B",
// packaging: "ENVELOPING",

container: "ASiC_E",
packaging: "ENVELOPED",
},
callback,
true
);
}

getSignedXmlWithEnvelopeBase64(callback) {
this.log("getSignedXmlWithEnvelopeBase64", arguments);
this.__implementation.getSignature(
Expand Down
28 changes: 14 additions & 14 deletions src/dbridge_js/inject-ditec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@ import { ditecX } from "./ditecx/ditecx";

type OriginalDitec = object;

const useProxy = false;
const useProxy = true;
const useProxyWithOriginal = useProxy && false;
export function inject(windowAny: { ditec?: OriginalDitec }): void {
console.log("Start inject");
console.log(windowAny.ditec);
console.log("Start inject. Original ditec:", windowAny.ditec);

if (windowAny.ditec) {
if (useProxy) {
import("./proxy").then(({ wrapWithProxy }) => {
windowAny.ditec = useProxyWithOriginal
? wrapWithProxy(windowAny.ditec)
: wrapWithProxy(ditecX);
});
} else {
windowAny.ditec = ditecX;
}
if (!windowAny.ditec) {
// TODO: maybe add whitelist
console.warn("Creating ditec object");
}

// windowAny.ditec = wrapWithProxy(ditecX);
if (useProxy) {
import("./proxy").then(({ wrapWithProxy }) => {
windowAny.ditec = useProxyWithOriginal
? wrapWithProxy(windowAny.ditec)
: wrapWithProxy(ditecX);
});
} else {
windowAny.ditec = ditecX;
}
}
79 changes: 54 additions & 25 deletions src/dbridge_js/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ const ignoredProps: PropertyKey[] = [

const logger = {
push(...rest) {
// console.log(...rest);
console.log(...rest);
log.push(...rest);
},
};

function getSpyHandler(prefix?: string, depth?: number) {
const spyHandler = {
get(target: object, prop: PropertyKey, receiver?: unknown) {
const spyHandler: ProxyHandler<object> = {
get(target: object, prop: PropertyKey, receiver?) {
// log.push({ target, prefix, prop, receiver });
// const wrappedTarget =
// typeof target === "function" ? wrapFunction(target) : target;
Expand All @@ -42,22 +42,50 @@ function getSpyHandler(prefix?: string, depth?: number) {
const name = `${prefix}.${prop.toString()}`;
const reflection = Reflect.get(target, prop, receiver);

if (typeof reflection == "function")
logger.push({
type: "get",
name,
target,
prop,
receiver,
});
logger.push({
type: "get",
name,
target,
prop,
receiver,
});

return depth < 3 &&
const returnNestedProxy =
depth < 4 &&
!ignoredProps.includes(prop) &&
(typeof reflection == "function" || typeof reflection == "object")
(typeof reflection == "function" || typeof reflection == "object");

return returnNestedProxy
? wrapWithProxy(reflection, name, depth + 1)
: reflection;
},

set(target: object, prop: PropertyKey, value, receiver?) {
const name = `${prefix}.${prop.toString()}`;
const ignoredNames = ["root.utils.generateGuid"];

logger.push({
type: "set",
name,
target,
prop,
value,
receiver,
});

if (
!Object.prototype.hasOwnProperty.call(target, prop) &&
!ignoredNames.includes(name)
) {
console.warn(
`setting property "${prop.toString()}" on "${prefix}" ${target}`
);
Reflect.set(target, prop, value, receiver);
}

return true;
},

// eslint-disable-next-line @typescript-eslint/ban-types
// construct(target: Function, argumentList, newTarget: Function) {
// console.log("construct", target, argumentList, newTarget);
Expand All @@ -69,18 +97,18 @@ function getSpyHandler(prefix?: string, depth?: number) {
const name = `${thisArg.__proxy_name}.${target.name}`;

// this causes infinite loop
if (
argumentList &&
argumentList[0] &&
argumentList[0]["onSuccess"] &&
typeof argumentList[0]["onSuccess"] === "function"
) {
const oldOnSuccess = argumentList[0]["onSuccess"];
argumentList[0]["onSuccess"] = function (...onSuccessArgs) {
logger.push({ type: "callback.onSuccess", name, onSuccessArgs });
return oldOnSuccess(...onSuccessArgs);
};
}
// if (
// argumentList &&
// argumentList[0] &&
// argumentList[0]["onSuccess"] &&
// typeof argumentList[0]["onSuccess"] === "function"
// ) {
// const oldOnSuccess = argumentList[0]["onSuccess"];
// argumentList[0]["onSuccess"] = function (...onSuccessArgs) {
// logger.push({ type: "callback.onSuccess", name, onSuccessArgs });
// return oldOnSuccess(...onSuccessArgs);
// };
// }

logger.push({ type: "apply", name, target, thisArg, argumentList });
return Reflect.apply(target, thisArg, argumentList);
Expand All @@ -94,6 +122,7 @@ export function wrapWithProxy<T extends object>(
prefix = "root",
depth = 0
): T & { __proxy_log: typeof log } {
console.log("wrapWithProxy", { target, prefix, depth });
if (typeof target !== "object" && typeof target !== "function") {
// console.log("skipping", typeof target, target);
return target;
Expand Down
Loading