Skip to content

Commit

Permalink
created models. they won't be used yet
Browse files Browse the repository at this point in the history
  • Loading branch information
looserouting committed Oct 9, 2024
1 parent 300a3a7 commit a94951a
Show file tree
Hide file tree
Showing 7 changed files with 163 additions and 0 deletions.
10 changes: 10 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# read initdb file to create database if database does not exist

# can I user http for wkd? this way i don't need certificates for "foreign" domains

# Search for key on website

# function as a key server
have to check the documentation how this works
keyserver.defaultDomain

# revoke key

## steps for revoking
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"nodemailer": "^6.9.15",
"nodemailer-openpgp": "^2.2.1",
"openpgp": "^5.11.2",
"sequelize": "^6.37.4",
"smtp-server": "^3.13.5",
"sqlite3": "^5.1.7",
"zbase32": "^2.0.3"
},
"devDependencies": {
Expand Down
51 changes: 51 additions & 0 deletions src/model/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import {DataTypes} from 'sequelize';

const defineConfig = (sequelize) => {
const Config = sequelize.define('Config',
{
parameter: {
type: DataTypes.STRING,
allowNull: false,
},
value: {
type: DataTypes.STRING,
allowNull: false,
}
});

return Config;
};

export default defineConfig;



/*
// WDK will available under openpgp.defaultDomain. The public key will be published here so we can receive encrypted mails.
// Verification links will use openpgp.defaultDomain. Because of that you'll need an entry in the Domain table for this domain.
dafaultDomain: positron-it.de
//When enabled the server will accept key for all domain ans will create a directory for each domain
acceptAllKeys: false
// a wks client will get this Submission Address when checking for one. The mail server will only access mails send to this receipient.
submissionAddress: "key-submission@positron-it.de"
// this is the private key for submissinoAddress. the service needs this key to sign mails and to decrypt mails if encrypted
pgpprivkey: "./submission.key"
// password for decrypting the PGPPrivateKey if encrypted
pgppass:
// this ist the public key for the submissionAddress. This key will be automatically publish so we can receive encrypted mails.
pgppubkey: "./positron-it.de/hu/54f6ry7x1qqtpor16txw5gdmdbbh6a73"
// for SMTP server and default web cert if no cert for sni found. typecally it's for the same domains a defaultVerifyDomain
defaultServerKey: "/etc/letsencrypt/live/openpgpkey.positron-it.de/privkey.pem"
defaultServerCert: "/etc/letsencrypt/live/openpgpkey.positron-it.de/cert.pem"
// SMTP Client
// set to true if you wand to use the sendmail to send mails. When set to true other SMTP options will be ignored
SMTPSendmail: true
// if you want to use an external server.
SMTPPort: 25
SMTPHost: 'postitron-it.de'
SMTPUser: 'yawksuser'
SMTPPassword: 'yakspassword'
*/
28 changes: 28 additions & 0 deletions src/model/domain.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import {DataTypes} from 'sequelize';

const defineDomain = (sequelize) => {
const Domain = sequelize.define('Domain',
{
name: {
type: DataTypes.STRING,
allowNull: false,
},
cert: {
type: DataTypes.STRING,
},
privateKey: {
type: DataTypes.STRING,
},
});
return Domain;
};

export default defineDomain;

// TODO domain has Many Keys

/*
name: "positron-it.de"
cert: "/etc/letsencrypt/live/openpgpkey.positron-it.de/privkey.pem"
key: "/etc/letsencrypt/live/openpgpkey.positron-it.de/cert.pem"
*/
26 changes: 26 additions & 0 deletions src/model/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Sequelize } from 'sequelize';
import definePendingRequest from './pendingRequest.js';
import defineKey from './key.js';
import defineConfig from './config.js';
import defineDomain from './domain.js'

// Initialize Sequelize (you can replace the SQLite connection with your actual database)
const sequelize = new Sequelize({
dialect: 'sqlite',
storage: ':memory:', // This sets up an in-memory SQLite database
});

// Initialize models
const Domain = defineDomain(sequelize);
const Key = defineKey(sequelize);
const pendingRequest = definePendingRequest(sequelize);
const Config = defineConfig(sequelize);

// Setup associations
pendingRequest.belongsTo(Key, {
foreignKey: 'email', // Foreign key column in pendingRequest
//as: 'key' // Alias for the relationship
});

// Export models and sequelize connection
export { sequelize, pendingRequest, Key , Config, Domain};
31 changes: 31 additions & 0 deletions src/model/key.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import {DataTypes} from 'sequelize';

const defineKey = (sequelize) => {
const Key = sequelize.define('Key',
{
email: {
type: DataTypes.STRING,
allowNull: false,
},
wkdHash: {
type: DataTypes.STRING,
allowNull: false
},
domain: {
type: DataTypes.STRING,
allowNull: false
},
key: {
type: DataTypes.STRING,
allowNull: false
},
status: {
type: DataTypes.ENUM('pending','published'),
allowNull: false
},
});

return Key;
};

export default defineKey;
15 changes: 15 additions & 0 deletions src/model/pendingRequest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { DataTypes } from 'sequelize';

const definePendingRequest = (sequelize) => {
const pendingRequest = sequelize.define('pendingRequest', {
token: {
type: DataTypes.STRING,
allowNull: false,
}
});

// You won't define associations here directly
return pendingRequest;
};

export default definePendingRequest;

0 comments on commit a94951a

Please sign in to comment.