Error catching for invalid certificates

merge-requests/2/merge
Bsian 2020-01-01 22:21:41 +00:00
parent 6390276306
commit 91c7b0c6f5
No known key found for this signature in database
GPG Key ID: 097FB9A291026091
3 changed files with 9 additions and 3 deletions

View File

@ -3,7 +3,7 @@ import { parseCert } from '@ghaiklor/x509';
import { Message } from 'eris'; import { Message } from 'eris';
import { Client } from '..'; import { Client } from '..';
import { Command, RichEmbed } from '../class'; import { Command, RichEmbed } from '../class';
import { parseCertificate } from '../functions'; import { parseCertificate, Certificate } from '../functions';
export default class Parse extends Command { export default class Parse extends Command {
constructor(client: Client) { constructor(client: Client) {
@ -26,7 +26,12 @@ export default class Parse extends Command {
return message.channel.createMessage(`***${this.client.stores.emojis.error} Cannot locate Validation directory.***`); return message.channel.createMessage(`***${this.client.stores.emojis.error} Cannot locate Validation directory.***`);
} }
if (!dir.length) return message.channel.createMessage(`***${this.client.stores.emojis.error} Cannot locate certificate.***`); if (!dir.length) return message.channel.createMessage(`***${this.client.stores.emojis.error} Cannot locate certificate.***`);
const cert = await parseCertificate(this.client, `${account.homepath}/Validation/${dir[0]}`); let cert: Certificate;
try {
cert = await parseCertificate(this.client, `${account.homepath}/Validation/${dir[0]}`);
} catch (error) {
if (error.message.includes('panic: Certificate PEM Encode == nil')) return message.channel.createMessage(`***${this.client.stores.emojis.error} Invalid certificate.***`);
}
// const cert = parseCert(`${account.homepath}/Validation/${dir[0]}`); // const cert = parseCert(`${account.homepath}/Validation/${dir[0]}`);
const subjectCommonName = cert.subject.commonName || 'Not Specified'; const subjectCommonName = cert.subject.commonName || 'Not Specified';
const subjectEmailAddress = cert.subject.emailAddress || 'Not Specified'; const subjectEmailAddress = cert.subject.emailAddress || 'Not Specified';

View File

@ -48,6 +48,7 @@ export default class Parseall extends Command {
else final.push(`${this.client.stores.emojis.success} **${a.username}** Expires in ${time}`); else final.push(`${this.client.stores.emojis.success} **${a.username}** Expires in ${time}`);
} catch (error) { } catch (error) {
if (error.message.includes('no such file or directory') || error.message.includes('File doesn\'t exist.')) final.push(`${this.client.stores.emojis.error} **${a.username}** Unable to locate certificate`); if (error.message.includes('no such file or directory') || error.message.includes('File doesn\'t exist.')) final.push(`${this.client.stores.emojis.error} **${a.username}** Unable to locate certificate`);
if (error.message.includes('panic: Certificate PEM Encode == nil')) final.push(`${this.client.stores.emojis.error} ** ${a.username}** Invalid certificate`);
else throw error; else throw error;
} }
}); });

View File

@ -1,4 +1,4 @@
export { default as checkLock } from './checkLock'; export { default as checkLock } from './checkLock';
export { default as dataConversion } from './dataConversion'; export { default as dataConversion } from './dataConversion';
export { default as checkSS } from './checkSS'; export { default as checkSS } from './checkSS';
export { default as parseCertificate } from './parseCertificate'; export { default as parseCertificate, Certificate } from './parseCertificate';