everyone
I’m trying use JavaScript to parse a PEM format certificate now. I’m expecting to get the
Basic Constraint value to distinguish whether a certificate the user uploaded is a CA.
The Basic Constraint value in the certificate is as follows:
My coding environment is Vue2 and jsrsasign v11.1.0 and nodejs v18.9.0.
My code is bellow.
<template>
<div class="parseCert">
<el-upload
class="uploadFile"
ref="upload"
drag
action="aa"
:on-change="onChange"
:auto-upload="false">
<i class="el-icon-upload"></i>
<div class="el-upload__text">Drag cert file to here</div>
</el-upload>
</div>
</template>
<script>
import { X509 } from 'jsrsasign'
export default {
data () {
return {
}
},
methods: {
onChange (file) {
let reader = new FileReader()
let cert = new X509()
reader.onload = function () {
cert.readCertPEM(reader.result)
cert.getSubject().array.forEach(e => {
console.log('ds: ' + e[0].ds + ', type: ' + e[0].type + ', value: ' + e[0].value)
}
)
// Here is I try to get the basicConstraints
// But it seems that it is nothing can be get
const basicConstraints = cert.getExtBasicConstraints()
console.log('Basic Constraints: ' + basicConstraints)
console.log(basicConstraints)
for (const key in basicConstraints) {
if (Object.prototype.hasOwnProperty.call(basicConstraints, key)) {
const value = basicConstraints[key];
console.log(`Key: ${key}, Value: ${value}`);
}
}
}
reader.readAsText(file.raw)
}
}
}
</script>
<style>
</style>
My code can’t get the Basic Constraint value and I have no idea how to fix.
Am I using the jsrsasign module by mistake?
There is any better or right way to achieve my goal?