Your IP : 216.73.216.52


Current Path : /snap/lxd/38450/share/lxd-ui/assets/
Upload File :
Current File : //snap/lxd/38450/share/lxd-ui/assets/CertificateGenerate-CHVdCnL9.js

import{r as m,f as v,h as C,q as y,k as S,j as e,d as t,u as I,c as R,b as M,i as A,N as F,R as w,s as T,l as E,A as L}from"./index-BsQN_SZU.js";const G=({onConfirm:a,onClose:i,isPasswordRequired:o})=>{const[n,r]=m.useState(o),c=v().shape({password:C(),passwordConfirm:C().oneOf([y("password"),""],"Passwords must match")}),s=S({initialValues:{password:"",passwordConfirm:""},validationSchema:c,onSubmit:x=>{a(x.password)}}),h=()=>{a("")};return e.jsxs(t.Modal,{close:i,title:"Create Certificate",buttonRow:e.jsx(e.Fragment,{children:n?e.jsx(t.ActionButton,{appearance:"positive",className:"u-no-margin--bottom",onClick:()=>{s.submitForm()},disabled:s.values.password!==s.values.passwordConfirm||s.values.password.length===0,children:"Generate and download"}):e.jsx(t.Button,{appearance:"positive",className:"u-no-margin--bottom",onClick:h,children:"Generate and download"})}),children:[e.jsx(t.Notification,{severity:"caution",className:"u-no-margin--bottom",children:"Passwords are required for client certificates on macOS. On other platforms, a password is optional."}),e.jsx(t.Switch,{label:"Password protected",checked:n,onChange:()=>{r(!n)}}),n&&e.jsxs(e.Fragment,{children:[e.jsx(t.Input,{id:"password",type:"password",label:"Password",onBlur:s.handleBlur,onChange:s.handleChange,value:s.values.password,error:s.touched.password?s.errors.password:null}),e.jsx(t.Input,{id:"passwordConfirm",type:"password",label:"Confirm password",onBlur:s.handleBlur,onChange:s.handleChange,value:s.values.passwordConfirm,error:s.touched.passwordConfirm?s.errors.passwordConfirm:null})]})]})},B=({isPasswordRequired:a})=>{const[i,o]=m.useState(!1),[n,r]=m.useState(!1),[c,s]=m.useState(null),h=()=>{r(!1)},x=()=>{r(!0)},N=f=>{h(),o(!0);const l=new Worker(new URL(""+new URL("certificate-DT5PfSbU.js",import.meta.url).href,import.meta.url),{type:"module"});l.onmessage=d=>{s(d.data),o(!1),k(`lxd-ui-${location.hostname}.pfx`,d.data.pfx),l.terminate()},l.onerror=d=>{console.error("Web Worker error:",d),o(!1),l.terminate()},l.postMessage(f)},k=(f,l)=>{const d=`data:application/octet-stream;base64,${l}`,j=document.createElement("a");j.href=d,j.download=f,j.click()};return e.jsxs(e.Fragment,{children:[n&&e.jsx(G,{onClose:h,onConfirm:N,isPasswordRequired:a}),e.jsxs("div",{children:[e.jsxs(t.Button,{onClick:x,disabled:i||c!==null,className:"u-no-margin--bottom",hasIcon:!0,"aria-label":`${i?"Generating":"Generate"} certificate`,children:[i?e.jsx(t.Icon,{className:"u-animation--spin",name:"spinner"}):e.jsx(t.Icon,{name:"begin-downloading",alt:"download"}),e.jsx("span",{children:i?"Generating":"Generate certificate"})]}),c!==null&&e.jsx(t.Icon,{name:"success"})]})]})},p="Firefox",g="Chrome on Linux",b="Chrome on Windows",_="Microsoft Edge",u="macOS",O=[p,g,b,_,u],P=()=>{const a=navigator.userAgent.toLowerCase(),i=a.includes("macintosh")||a.includes("mac os"),o=a.includes("windows"),n=a.includes("linux"),r=a.includes("edg/"),c=a.includes("firefox"),s=a.includes("chrome");return c?p:i?u:r?_:s&&o?b:s&&n?g:p},W=({isBearerToken:a=!1})=>{const[i,o]=m.useState(P()),n=e.jsxs(e.Fragment,{children:[e.jsxs("li",{className:"p-list__item",children:["In the modal that appears, click ",e.jsx("b",{children:"Import..."})]}),e.jsxs("li",{className:"p-list__item",children:["Follow the instructions in the Certificate Import Wizard. When prompted with ",e.jsx("b",{children:"File to Import"}),", click ",e.jsx("b",{children:"Browse"})," and choose the certificate you downloaded. In order to see the certificate file, ensure that the file type picker is set to"," ",e.jsx("b",{children:"Personal Information Exchange (*.pfx;*.p12)"}),"."]}),e.jsx("li",{className:"p-list__item",children:e.jsx("b",{children:"Restart the browser."})})]}),r=e.jsxs("li",{className:"p-list__item u-clearfix",children:["Create and download a client certificate:",e.jsx(B,{isPasswordRequired:i===u})]}),c=e.jsxs(e.Fragment,{children:[e.jsx(t.Tabs,{links:O.map(s=>({label:s,active:s===i,onClick:()=>{o(s)}}))}),i===p&&e.jsx("div",{role:"tabpanel","aria-label":"firefox",children:e.jsxs("ul",{className:"p-list--divided u-no-margin--bottom",children:[r,e.jsxs("li",{className:"p-list__item",children:["Go to Firefox’s privacy settings:",e.jsx("pre",{className:"p-code-snippet__block u-no-margin--bottom",children:e.jsx("code",{children:"about:preferences#privacy"})})]}),e.jsxs("li",{className:"p-list__item",children:["Scroll down to the certificates section and click"," ",e.jsx("b",{children:"View Certificates"})]}),e.jsxs("li",{className:"p-list__item",children:["In the modal that appears, go to ",e.jsx("b",{children:"Your certificates"})," and click Import"]}),e.jsx("li",{className:"p-list__item",children:"Select the .pfx file you just downloaded. If you created a password for the certificate, type it in now."}),e.jsx("li",{className:"p-list__item",children:e.jsx("b",{children:"Restart the browser."})})]})}),i===g&&e.jsx("div",{role:"tabpanel","aria-label":"chrome linux",children:e.jsxs("ul",{className:"p-list--divided u-no-margin--bottom",children:[r,e.jsxs("li",{className:"p-list__item",children:["Go to the import certificate page within Chrome's certificate manager:",e.jsx("pre",{className:"p-code-snippet__block u-no-margin--bottom",children:e.jsx("code",{children:"chrome://certificate-manager/clientcerts/platformclientcerts"})})]}),e.jsxs("li",{className:"p-list__item",children:["Select ",e.jsx("b",{children:"Import"})," and choose the .pfx file you just downloaded. If you created a password for the certificate, type it in now."]}),e.jsx("li",{className:"p-list__item",children:e.jsx("b",{children:"Restart the browser."})})]})}),i===b&&e.jsx("div",{role:"tabpanel","aria-label":"chrome windows",children:e.jsxs("ul",{className:"p-list--divided u-no-margin--bottom",children:[r,e.jsxs("li",{className:"p-list__item",children:["Go to Chrome's certificate settings:",e.jsx("pre",{className:"p-code-snippet__block u-no-margin--bottom",children:e.jsx("code",{children:"chrome://settings/certificates"})})]}),e.jsxs("li",{className:"p-list__item",children:["Near the bottom of the page, click ",e.jsx("b",{children:"Manage certificates"})]}),e.jsxs("li",{className:"p-list__item",children:["Make sure"," ",e.jsx("b",{children:"Use imported local certificates from your operating system"})," ","is toggled on, and click"," ",e.jsx("b",{children:"Manage imported certificates from Windows"})," "]}),n]})}),i===_&&e.jsx("div",{role:"tabpanel","aria-label":"edge windows",children:e.jsxs("ul",{className:"p-list--divided u-no-margin--bottom",children:[r,e.jsxs("li",{className:"p-list__item",children:["Go to Edge's certificate settings:",e.jsx("pre",{className:"p-code-snippet__block u-no-margin--bottom",children:e.jsx("code",{children:"edge://settings/privacy"})})]}),e.jsxs("li",{className:"p-list__item",children:["Under ",e.jsx("b",{children:"Security"}),", click ",e.jsx("b",{children:"Manage certificates"})]}),n]})}),i===u&&e.jsx("div",{role:"tabpanel","aria-label":"safari macos",children:e.jsxs("ul",{className:"p-list--divided u-no-margin--bottom",children:[r,e.jsxs("li",{className:"p-list__item",children:["Launch the ",e.jsx("b",{children:"Keychain Access app"})," (you will need to authenticate using your mac’s login credentials)"]}),e.jsxs("li",{className:"p-list__item",children:["Import the certificate file that was created earlier. This can be done either by dragging the file from Finder onto Keychain Access, or with ",e.jsx("b",{children:" File > Import Items..."})]}),e.jsx("li",{className:"p-list__item",children:"Unlock the certificate by typing in the password used to create it."}),e.jsx("li",{className:"p-list__item",children:e.jsx("b",{children:"Restart the browser."})})]})})]});return a?c:e.jsx(t.Row,{children:e.jsx(t.Col,{size:10,children:c})})},U=()=>{const{isAuthenticated:a,isAuthLoading:i,authMethod:o}=I(),n=R(),{data:r}=M(),c=r?.client_certificate,s=o===L.BEARER;return i?e.jsx(t.Spinner,{className:"u-loader",text:"Loading...",isMainComponent:!0}):a&&A(o)?e.jsx(F,{to:`${w}/ui`,replace:!0}):e.jsx(t.CustomLayout,{mainClassName:T("certificates",{"certificates-with-bearer-token":s}),children:e.jsxs(t.Row,{children:[s&&e.jsx(E,{variant:"horizontal",step2Name:"Create TLS identity"}),!s&&e.jsx(t.Col,{size:1}),e.jsxs(t.Col,{size:s?12:10,children:[e.jsxs(t.Notification,{actions:c?[]:[{label:"I already have a client certificate",onClick:()=>{n(`${w}/ui/login/certificate-add`)}}],title:"TLS login",severity:"information",children:["LXD uses mutual TLS for server client-server authentication. Your browser must have a client certificate installed and selected in order to proceed."," ",e.jsxs("a",{href:"https://github.com/canonical/lxd-ui/wiki/Authentication-Setup-FAQ",target:"_blank",rel:"noopener noreferrer",children:["Authentication Setup FAQ",e.jsx(t.Icon,{className:"external-link-icon",name:"external-link"})]})]}),c&&e.jsx(t.Notification,{actions:[{label:`Skip to step 2: ${s?"Create TLS identity":"Identity trust token"}`,onClick:()=>{n(`${w}/ui/login/certificate-add`)}}],title:"Client certificate already present",severity:"positive",children:"It looks like you already have a client certificate installed and selected, skip to the next step."}),e.jsx(W,{})]})]})})};export{U as default};