Izstrādātājiem & AI

Vairogs API & MCP

Piekļūstiet sava seifa saturam programmatiski ar zero-knowledge šifrēšanu.

Drošība & Šifrēšana

Zero-knowledge arhitektūra un kriptogrāfiskie standarti

Vairogs API izmanto zero-knowledge arhitektūru, kas nozīmē, ka serveris nekad neredz atšifrētus datus. Visa šifrēšana un atšifrēšana notiek klienta pusē.

AES-256-GCM

Militārā līmeņa simetriskā šifrēšana ar autentifikāciju.

X25519

Moderna eliptisko līkņu kriptogrāfija atslēgu apmaiņai.

PBKDF2

100,000 iterācijas atslēgu atvasināšanai.

Zero-Knowledge

Serveris nekad neredz atšifrētus datus.

Šifrēšanas Arhitektūra

┌─────────────────────────────────────────────────────────────────┐
│                     VIENUMA ŠIFRĒŠANA                           │
├─────────────────────────────────────────────────────────────────┤
│                                                                 │
│  ┌─────────────┐                      ┌─────────────────────┐   │
│  │ Plaintext   │                      │ Encrypted Item      │   │
│  │ Data        │  ──── AES-256-GCM ───>  │ (encryptedData)     │   │
│  └─────────────┘                      └─────────────────────┘   │
│        │                                       │                │
│        │                                       │                │
│        v                                       v                │
│  ┌─────────────┐                      ┌─────────────────────┐   │
│  │ Random DEK  │  ──── NaCl Box ────> │ Key Slots           │   │
│  │ (32 bytes)  │                      │ (encrypted DEK      │   │
│  └─────────────┘                      │  per recipient)     │   │
│                                       └─────────────────────┘   │
│                                                                 │
└─────────────────────────────────────────────────────────────────┘

┌─────────────────────────────────────────────────────────────────┐
│                     KEY SLOTS SISTĒMA                           │
├─────────────────────────────────────────────────────────────────┤
│                                                                 │
│  Katram vienumam var būt vairāki "key slots":                  │
│                                                                 │
│  ┌─────────────────┐   ┌─────────────────┐                     │
│  │ Slot: "main"    │   │ Slot: "vgtk_a_" │                     │
│  │ (Galvenais      │   │ (MCP/API        │                     │
│  │  lietotājs)     │   │  atslēga)       │                     │
│  └─────────────────┘   └─────────────────┘                     │
│         │                      │                               │
│         v                      v                               │
│  ┌─────────────────┐   ┌─────────────────┐                     │
│  │ User PublicKey  │   │ MCP PublicKey   │                     │
│  │ (asymmetric     │   │ (derived from   │                     │
│  │  master key)    │   │  vgtk_d_ key)   │                     │
│  └─────────────────┘   └─────────────────┘                     │
│                                                                 │
└─────────────────────────────────────────────────────────────────┘

DEK (Data Encryption Key)

  • Unikāla 32-baitu gadījuma atslēga katram vienumam
  • Izmanto AES-256-GCM šifrēšanai
  • Nekad netiek glabāts nešifrēts

Key Slots

  • DEK šifrēts ar NaCl box katram saņēmējam
  • Ļauj vairākiem klientiem piekļūt vienam vienumam
  • Katrs slot satur: encryptedDEK, nonce, senderPublicKey

Kriptogrāfiskās Konstantes

Tag API v2 Parametri

Šīs konstantes jāizmanto, implementējot Tag API v2 atšifrēšanu.

typescript
// Atslēgu atvasināšana
const MCP_SALT = 'vairogs-mcp-key-derivation-v1'
const PBKDF2_ITERATIONS = 100000
const KEY_LENGTH = 32  // bytes

// AES-256-GCM parametri
const AES_KEY_LENGTH = 32    // 256 bits
const IV_LENGTH = 12         // 96 bits (GCM standarts)
const AUTH_TAG_LENGTH = 16   // 128 bits

// NaCl Box parametri
const NACL_NONCE_LENGTH = 24    // bytes
const NACL_PUBLIC_KEY_LENGTH = 32
const NACL_SECRET_KEY_LENGTH = 32

// Key Slot identifikatori
const MAIN_KEY_SLOT = 'main'
const MCP_KEY_PREFIX_LENGTH = 15  // Pirmie 15 simboli no access key

Atslēgas Atvasināšana

typescript
import nacl from 'tweetnacl'
import crypto from 'crypto'

// Atvasina X25519 atslēgu pāri no Decryption Key
function deriveKeypair(decryptKey: string) {
  // 1. PBKDF2 ar 100k iterācijām
  const seed = crypto.pbkdf2Sync(
    decryptKey,           // vgtk_d_xxx atslēga
    MCP_SALT,             // 'vairogs-mcp-key-derivation-v1'
    PBKDF2_ITERATIONS,    // 100000
    KEY_LENGTH,           // 32
    'sha256'
  )

  // 2. Ģenerē NaCl Box keypair no seed
  const keypair = nacl.box.keyPair.fromSecretKey(new Uint8Array(seed))

  return {
    publicKey: keypair.publicKey,   // Atbilst mcpPublicKey serverī
    secretKey: keypair.secretKey    // Izmanto atšifrēšanai
  }
}

Atšifrēšanas Process

1

Atvasini keypair no Decrypt Key

Izmanto PBKDF2 + NaCl box.keyPair.fromSecretKey()

2

Atrodi pareizo Key Slot

Meklē slot ar keyId = pirmie 15 simboli no Access Key (vgtk_a_xxxxxxx)

3

Atšifrē DEK ar NaCl box.open

Izmanto encryptedDEK, nonce, senderPublicKey no slot un savu secretKey

4

Atšifrē datus ar AES-GCM

Izmanto DEK un IV no vienuma, lai atšifrētu encryptedData

typescript
// Pilns atšifrēšanas piemērs
async function decryptItem(item: EncryptedItem, keypair: nacl.BoxKeyPair, accessKey: string) {
  // 1. Atrast pareizo key slot
  const mcpKeyPrefix = accessKey.substring(0, 15)  // 'vgtk_a_xxxxxxx'
  const keySlot = item.keySlots.find(s => s.keyId === mcpKeyPrefix)

  if (!keySlot) throw new Error('Key slot not found')

  // 2. Atšifrēt DEK ar NaCl box
  const encryptedDEK = base64ToUint8Array(keySlot.encryptedDEK)
  const nonce = base64ToUint8Array(keySlot.nonce)
  const senderPublicKey = base64ToUint8Array(keySlot.senderPublicKey)

  const dek = nacl.box.open(encryptedDEK, nonce, senderPublicKey, keypair.secretKey)
  if (!dek) throw new Error('Failed to decrypt DEK')

  // 3. Atšifrēt datus ar AES-GCM
  const iv = base64ToUint8Array(item.iv)
  const encryptedData = base64ToUint8Array(item.encryptedData)

  const decipher = crypto.createDecipheriv('aes-256-gcm', Buffer.from(dek), iv)
  const authTag = encryptedData.slice(-16)  // Pēdējie 16 baiti
  const ciphertext = encryptedData.slice(0, -16)

  decipher.setAuthTag(authTag)
  const decrypted = Buffer.concat([decipher.update(ciphertext), decipher.final()])

  return JSON.parse(decrypted.toString('utf8'))
}

Drošības Apsvērumi

Decrypt Key nekad nesūtiet serverim

Access Key ir paredzēta HTTP pieprasījumiem. Decrypt Key izmanto tikai lokāli.

Serveris glabā tikai hash

Access Key serverī tiek salīdzināta ar bcrypt hash, nevis plaintext.

Unikāls IV katram vienumam

Katram vienumam tiek ģenerēts jauns 12-baitu IV, nodrošinot kriptogrāfisku drošību.

Atslēgu glabāšana

Glabājiet atslēgas šifrētā veidā vai izmantojiet secret management sistēmas (Vault, AWS Secrets Manager).

Atslēgu rotācija

Regulāri izveidojiet jaunas API atslēgas un dzēsiet vecās. Ieteicams vismaz reizi 90 dienās.

Atbalstītie Algoritmi

MērķisAlgoritmsParametri
Datu šifrēšanaAES-256-GCM256-bit key, 96-bit IV, 128-bit auth tag
Atslēgu apmaiņaX25519 (NaCl box)256-bit keys, 192-bit nonce
Atslēgu atvasināšanaPBKDF2-SHA256100,000 iterācijas, 32-byte output
API key hashbcryptCost factor 12