cert); $model->crt_parse = collect(openssl_x509_parse($model->cert)); if ($model->csr) { $model->public_key = collect(openssl_pkey_get_details(openssl_csr_get_public_key($model->csr))); } }); } /* ABSTRACT */ /** * Search for a record * * @param $query * @param string $term * @return mixed */ public function scopeSearch($query,string $term) { // @todo } /* INTERFACES */ /** * Return the Cert DN * * @return string */ public function getServiceDescriptionAttribute(): string { if ($this->cert) return Arr::get($this->crt_parse,'name'); else { $dn = ''; $dna = openssl_csr_get_subject($this->csr); foreach ($dna as $k=>$v) { if ($dn) $dn .= ','; $dn .= sprintf('%s=%s',$k,$v); } return $dn; } } /** * Return the Certificate Expiry Date */ public function getServiceExpireAttribute(): ?Carbon { return $this->cert ? Carbon::createFromTimestamp($this->crt_parse->get('validTo_time_t')) : NULL; } /** * Return the Cert Name * * @return string */ public function getServiceNameAttribute(): string { return $this->cert ? Arr::get($this->crt_parse,'subject.CN') : Arr::get(openssl_csr_get_subject($this->csr),'CN',''); } /** * Certificates have no contract and can be cancelled anytime. * * @return bool */ public function inContract(): bool { return FALSE; } /* METHODS */ /** * @return Carbon|null * @deprecated use getServiceExpireAttribute() */ public function getValidToAttribute() { abort(500,'use getServiceExpireAttribute'); } }