Skip to content

Commit

Permalink
fix(mitm): add cert logging
Browse files Browse the repository at this point in the history
fix(puppet): stablilize dom storage flush
  • Loading branch information
blakebyrnes committed Jan 11, 2022
1 parent 2b50b4d commit d6dde28
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion core/lib/Tab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ export default class Tab
const errors: Error[] = [];

try {
await this.puppetPage.domStorageTracker.flush(5e3);
await this.puppetPage.domStorageTracker.finalFlush(5e3);
} catch (error) {
if (!error.message.includes('Target closed') && !(error instanceof CanceledPromiseError)) {
errors.push(error);
Expand Down
2 changes: 1 addition & 1 deletion interfaces/IPuppetDomStorageTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default interface IPuppetDomStorageTracker {
storageForOrigin: IDomStorageForOrigin;
}[]
>;
flush(timeoutMs?: number): Promise<void>;
finalFlush(timeoutMs?: number): Promise<void>;
}

export interface IPuppetStorageEvents {
Expand Down
11 changes: 9 additions & 2 deletions mitm-socket/go/generate_cert.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import (
"crypto/x509"
"crypto/x509/pkix"
"encoding/pem"
"errors"
"fmt"
"math/big"
"log"
"net"
"os"
"sync/atomic"
Expand Down Expand Up @@ -39,6 +41,7 @@ type CertConfig struct {
func readCertFromDisk(file string) (*x509.Certificate, error) {

bytes, err := os.ReadFile(file)

if err != nil {
return nil, err
}
Expand Down Expand Up @@ -76,15 +79,19 @@ func NewAuthority() (*x509.Certificate, *rsa.PrivateKey, error) {
var caKeyFile string = "caKey.der"

certFromDisk, err := readCertFromDisk(caFile)
if err == nil {

if err != nil && !errors.Is(err, os.ErrNotExist) {
log.Printf("Error reading cert from disk", caFile, err)
} else if err == nil {
keyFromDisk, err := readPrivateKeyFromDisk(caKeyFile)
if err != nil {
fmt.Printf("Error reading private key from disk", caKeyFile, err)
log.Printf("Error reading private key from disk", caKeyFile, err)
} else {
return certFromDisk, keyFromDisk, nil
}
}


// Generating the private key that will be used for domain certificates
priv, err := rsa.GenerateKey(rand.Reader, 2048)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion mitm-socket/lib/BaseIpcHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export default abstract class BaseIpcHandler {

private onChildProcessStderr(message: string): void {
if (this.isClosing) return;
this.logger.info(`${this.handlerName}.stderr: ${message}`);
this.logger.error(`${this.handlerName}.stderr: ${message}`);
}

private spawnChild(): void {
Expand Down
6 changes: 5 additions & 1 deletion puppet-chrome/lib/DomStorageTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ export class DomStorageTracker
this.cancelPendingEvents('DomStorageTracker closed');
}

public async flush(timeoutMs = 30e3): Promise<void> {
public async finalFlush(timeoutMs = 30e3): Promise<void> {
eventUtils.removeEventListeners(this.registeredEvents);
await Promise.race([
this.processingPromise,
new Promise<void>(resolve => setTimeout(resolve, timeoutMs ?? 0)),
Expand Down Expand Up @@ -294,6 +295,8 @@ export class DomStorageTracker
this.indexedDBContentUpdatingOrigins.add(securityOrigin);

const timestamp = Date.now();
const resolvable = new Resolvable<void>();
this.processingPromise = this.processingPromise.then(() => resolvable.promise);
try {
const db = await this.getLatestIndexedDB(securityOrigin, databaseName);
const objectStore = db.objectStores.find(x => x.name === objectStoreName);
Expand Down Expand Up @@ -329,6 +332,7 @@ export class DomStorageTracker
});
} finally {
this.indexedDBContentUpdatingOrigins.delete(securityOrigin);
resolvable.resolve();
}
}

Expand Down

0 comments on commit d6dde28

Please sign in to comment.