173 lines
11 KiB
PHP
173 lines
11 KiB
PHP
{{-- PL0XI0N trousseau — la gestion des clés GPG (couche window.jOSGpg).
|
|
Génère MA paire (privée chiffrée par passphrase, jamais hors du navigateur),
|
|
partage ma clé PUBLIQUE (à donner à mes potes), importe les leurs. Une fois
|
|
déverrouillé, le ploxion `chat` peut chiffrer/déchiffrer. Admin-only.
|
|
window.jOSApps['trousseau']. mount(c, ctx) -> { unmount }. --}}
|
|
<style>
|
|
.tr { display:flex; flex-direction:column; height:100%; background:#06090d;
|
|
color:rgba(220,232,240,.92); font-family:ui-sans-serif,system-ui,sans-serif; font-size:.82rem; }
|
|
.tr__bar { flex:0 0 auto; display:flex; align-items:center; gap:8px; padding:8px 11px; border-bottom:1px solid rgba(120,200,255,.18); }
|
|
.tr__t { font-weight:700; letter-spacing:.04em; color:rgba(150,210,255,.95); }
|
|
.tr__st { margin-left:auto; font-size:.62rem; font-family:ui-monospace,monospace; padding:1px 8px; border-radius:20px; border:1px solid; }
|
|
.tr__st.lock { color:rgba(255,180,120,.95); border-color:rgba(255,180,120,.45); }
|
|
.tr__st.open { color:rgba(120,230,160,.95); border-color:rgba(120,230,160,.5); }
|
|
.tr__st.none { color:rgba(170,185,210,.7); border-color:rgba(170,185,210,.35); }
|
|
.tr__body { flex:1; min-height:0; overflow-y:auto; padding:11px 12px; display:flex; flex-direction:column; gap:11px; }
|
|
.tr__card { border:1px solid rgba(120,160,230,.18); border-radius:10px; padding:10px 11px; background:rgba(16,24,38,.45); }
|
|
.tr__h { font-size:.64rem; text-transform:uppercase; letter-spacing:.05em; color:rgba(150,185,225,.6); margin-bottom:7px; }
|
|
.tr label { display:block; font-size:.66rem; color:rgba(170,195,225,.7); margin:6px 0 2px; }
|
|
.tr input, .tr textarea { width:100%; box-sizing:border-box; background:rgba(0,0,0,.35);
|
|
border:1px solid rgba(120,160,230,.28); border-radius:8px; color:#e8f2fa; padding:7px 9px;
|
|
font:0.78rem ui-sans-serif,system-ui; }
|
|
.tr textarea { resize:vertical; min-height:62px; font-family:ui-monospace,monospace; font-size:.66rem; }
|
|
.tr input:focus, .tr textarea:focus { outline:none; border-color:rgba(120,200,255,.55); }
|
|
.tr__btn { cursor:pointer; border-radius:8px; padding:6px 13px; font-size:.74rem; margin-top:8px;
|
|
border:1px solid rgba(120,200,255,.55); background:rgba(60,120,180,.3); color:#fff; }
|
|
.tr__btn:hover { background:rgba(70,140,210,.42); }
|
|
.tr__btn[disabled] { opacity:.5; cursor:not-allowed; }
|
|
.tr__btn.ghost { background:none; border-color:rgba(150,180,220,.3); color:rgba(190,210,230,.78); }
|
|
.tr__btn.danger { border-color:rgba(255,120,120,.45); color:rgba(255,170,170,.9); }
|
|
.tr__fpr { font-family:ui-monospace,monospace; font-size:.62rem; color:rgba(150,200,255,.8); word-break:break-all; }
|
|
.tr__ct { display:flex; align-items:center; gap:8px; padding:5px 0; border-bottom:1px solid rgba(120,160,230,.1); }
|
|
.tr__ct:last-child { border-bottom:0; }
|
|
.tr__ctn { font-weight:600; color:#fff; }
|
|
.tr__x { margin-left:auto; cursor:pointer; background:none; border:0; color:rgba(255,140,140,.7); font-size:.9rem; }
|
|
.tr__msg { font-size:.66rem; min-height:12px; margin-top:5px; }
|
|
.tr__msg.err { color:rgba(255,150,150,.9); }
|
|
.tr__msg.ok { color:rgba(120,230,160,.9); }
|
|
.tr__empty { color:rgba(190,212,228,.5); font-size:.72rem; }
|
|
.tr__hint { font-size:.62rem; color:rgba(150,180,220,.55); margin-top:4px; line-height:1.4; }
|
|
</style>
|
|
<script>
|
|
(function () {
|
|
function esc(s) { return window.jOSb.esc(s); }
|
|
|
|
function describe() {
|
|
var G = window.jOSGpg;
|
|
if (!G) return { v: 1, id: 'trousseau', title: 'Trousseau', icon: '🔑', items: [{ p: 1, kind: 'text', label: 'trousseau', value: 'couche GPG indisponible' }] };
|
|
var s = G.state();
|
|
return { v: 1, id: 'trousseau', title: 'Trousseau', icon: '🔑', items: [
|
|
{ p: 1, kind: 'stat', label: s.unlocked ? '🔓 déverrouillé' : (s.hasKey ? '🔒 verrouillé' : 'pas de clé'), value: ((s.contacts || []).length) + ' contacts' }
|
|
] };
|
|
}
|
|
function mount(container, ctx) {
|
|
var alive = true;
|
|
var G = window.jOSGpg;
|
|
|
|
function render() {
|
|
if (!alive) return;
|
|
if (!G) {
|
|
container.innerHTML = '<div class="tr"><div class="tr__body"><div class="tr__empty">couche GPG indisponible.</div></div></div>';
|
|
return;
|
|
}
|
|
var s = G.state();
|
|
var stCls = s.unlocked ? 'open' : (s.hasKey ? 'lock' : 'none');
|
|
var stTxt = s.unlocked ? '🔓 déverrouillé' : (s.hasKey ? '🔒 verrouillé' : 'pas de clé');
|
|
|
|
var body = '';
|
|
if (!s.hasKey) {
|
|
body =
|
|
'<div class="tr__card"><div class="tr__h">crée ta clé</div>'
|
|
+ '<label>nom (visible par tes potes)</label><input data-f="name" placeholder="ex: RS-7" maxlength="80">'
|
|
+ '<label>email (optionnel)</label><input data-f="email" placeholder="ex: rs-7@…" maxlength="120">'
|
|
+ '<label>passphrase (protège ta clé privée — retiens-la)</label><input data-f="pass" type="password" placeholder="passphrase">'
|
|
+ '<button class="tr__btn" data-act="gen">générer ma paire de clés</button>'
|
|
+ '<div class="tr__msg" data-msg></div>'
|
|
+ '<div class="tr__hint">La clé privée reste dans ce navigateur (chiffrée par ta passphrase). On partage seulement la PUBLIQUE.</div></div>';
|
|
} else if (!s.unlocked) {
|
|
body =
|
|
'<div class="tr__card"><div class="tr__h">déverrouille — ' + esc(s.me.name) + '</div>'
|
|
+ '<div class="tr__fpr">' + esc(s.me.fpr) + '</div>'
|
|
+ '<label>passphrase</label><input data-f="pass" type="password" placeholder="ta passphrase" autofocus>'
|
|
+ '<button class="tr__btn" data-act="unlock">déverrouiller</button>'
|
|
+ '<button class="tr__btn ghost" data-act="forget">oublier cette clé</button>'
|
|
+ '<div class="tr__msg" data-msg></div></div>';
|
|
} else {
|
|
body =
|
|
'<div class="tr__card"><div class="tr__h">ma clé — ' + esc(s.me.name) + '</div>'
|
|
+ '<div class="tr__fpr">' + esc(s.me.fpr) + '</div>'
|
|
+ '<label>ma clé PUBLIQUE (à donner à tes potes)</label>'
|
|
+ '<textarea data-pub readonly onclick="this.select()">' + esc(G.myPub()) + '</textarea>'
|
|
+ '<button class="tr__btn" data-act="copy">copier ma clé publique</button>'
|
|
+ '<button class="tr__btn ghost" data-act="lock">verrouiller</button>'
|
|
+ '<div class="tr__msg" data-msg></div></div>'
|
|
|
|
+ '<div class="tr__card"><div class="tr__h">importer un contact</div>'
|
|
+ '<label>colle la clé PUBLIQUE de ton pote</label>'
|
|
+ '<textarea data-imp placeholder="-----BEGIN PGP PUBLIC KEY BLOCK-----"></textarea>'
|
|
+ '<button class="tr__btn" data-act="import">importer</button>'
|
|
+ '<div class="tr__msg" data-msg2></div></div>'
|
|
|
|
+ '<div class="tr__card"><div class="tr__h">contacts · ' + s.contacts.length + '</div>'
|
|
+ (s.contacts.length
|
|
? s.contacts.map(function (c) {
|
|
return '<div class="tr__ct"><span class="tr__ctn">' + esc(c.name) + '</span>'
|
|
+ '<span class="tr__fpr">' + esc(c.fpr.slice(0, 16)) + '…</span>'
|
|
+ '<button class="tr__x" data-rm="' + esc(c.fpr) + '" title="retirer">✕</button></div>';
|
|
}).join('')
|
|
: '<div class="tr__empty">aucun contact — importe la clé publique d\'un pote pour lui écrire chiffré.</div>')
|
|
+ '</div>';
|
|
}
|
|
|
|
container.innerHTML =
|
|
'<div class="tr">'
|
|
+ ' <div class="tr__bar"><span class="tr__t">🔑 Trousseau</span><span class="tr__st ' + stCls + '">' + stTxt + '</span></div>'
|
|
+ ' <div class="tr__body">' + body + '</div>'
|
|
+ '</div>';
|
|
wire();
|
|
}
|
|
|
|
function msg(sel, text, ok) {
|
|
var e = container.querySelector(sel); if (!e) return;
|
|
e.textContent = text || ''; e.className = 'tr__msg' + (text ? (ok ? ' ok' : ' err') : '');
|
|
}
|
|
function val(f) { var e = container.querySelector('[data-f="' + f + '"]'); return e ? e.value : ''; }
|
|
|
|
function wire() {
|
|
container.querySelectorAll('[data-act]').forEach(function (b) {
|
|
b.addEventListener('click', function () { act(b.getAttribute('data-act'), b); });
|
|
});
|
|
container.querySelectorAll('[data-rm]').forEach(function (b) {
|
|
b.addEventListener('click', function () { G.removeContact(b.getAttribute('data-rm')); });
|
|
});
|
|
}
|
|
|
|
function act(a, btn) {
|
|
if (a === 'gen') {
|
|
var name = val('name'), email = val('email'), pass = val('pass');
|
|
if (!pass) return msg('[data-msg]', 'choisis une passphrase');
|
|
btn.disabled = true; msg('[data-msg]', 'génération… (quelques secondes)', true);
|
|
G.generate({ name: name, email: email, passphrase: pass })
|
|
.catch(function (e) { msg('[data-msg]', e.message || 'échec'); if (alive) btn.disabled = false; });
|
|
} else if (a === 'unlock') {
|
|
var p = val('pass'); btn.disabled = true; msg('[data-msg]', 'déverrouillage…', true);
|
|
G.unlock(p).catch(function (e) { msg('[data-msg]', e.message || 'échec'); if (alive) btn.disabled = false; });
|
|
} else if (a === 'lock') { G.lock(); }
|
|
else if (a === 'forget') { if (confirm('Oublier cette clé ? Tu ne pourras plus déchiffrer les anciens messages sans la sauvegarde.')) G.forget(); }
|
|
else if (a === 'copy') {
|
|
var ta = container.querySelector('[data-pub]'); if (ta) { ta.select();
|
|
if (navigator.clipboard) navigator.clipboard.writeText(ta.value).then(function(){ msg('[data-msg]', 'copiée ✓', true); }, function(){ document.execCommand('copy'); msg('[data-msg]', 'copiée ✓', true); });
|
|
else { document.execCommand('copy'); msg('[data-msg]', 'copiée ✓', true); } }
|
|
} else if (a === 'import') {
|
|
var imp = container.querySelector('[data-imp]'); var armored = imp ? imp.value.trim() : '';
|
|
if (!armored) return msg('[data-msg2]', 'colle une clé publique');
|
|
btn.disabled = true; msg('[data-msg2]', 'import…', true);
|
|
G.importContact(armored)
|
|
.then(function (r) { msg('[data-msg2]', (r.added ? 'ajouté' : 'mis à jour') + ' : ' + r.name, true); })
|
|
.catch(function (e) { msg('[data-msg2]', e.message || 'échec'); if (alive) btn.disabled = false; });
|
|
}
|
|
}
|
|
|
|
// re-render sur tout changement d'état du trousseau (gen/unlock/import/...)
|
|
if (G && G.on) G.on(function () { render(); });
|
|
if (G && G.ensureLib) G.ensureLib().catch(function () {}); // précharge la lib
|
|
render();
|
|
|
|
return { unmount: function () { alive = false; container.innerHTML = ''; } };
|
|
}
|
|
|
|
window.jOSApps = window.jOSApps || {};
|
|
window.jOSApps['trousseau'] = { manifest: { id: 'trousseau', name: 'Trousseau', icon: '🔑' }, mount: mount, describe: describe };
|
|
})();
|
|
</script>
|