Skip to content

Commit b1d153a

Browse files
committed
Change Attribute/UserCertificate into Syntax/Certificate for any Certificate attributes. Add Syntax/CertificateList.
1 parent 8b0af50 commit b1d153a

File tree

8 files changed

+76
-29
lines changed

8 files changed

+76
-29
lines changed

app/Classes/LDAP/Attribute.php

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ class Attribute implements \Countable, \ArrayAccess
3737
// The objectclasses of the entry that has this attribute
3838
protected(set) Collection $oc;
3939

40+
private const SYNTAX_CERTIFICATE = '1.3.6.1.4.1.1466.115.121.1.8';
41+
private const SYNTAX_CERTIFICATE_LIST = '1.3.6.1.4.1.1466.115.121.1.9';
42+
4043
/*
4144
# Has the attribute been modified
4245
protected $modified = false;
@@ -123,6 +126,11 @@ public function __construct(string $dn,string $name,array $values,array $oc=[])
123126
*/
124127
}
125128

129+
public function __call(string $name,array $arguments)
130+
{
131+
abort(555,'Method not handled: '.$name);
132+
}
133+
126134
public function __get(string $key): mixed
127135
{
128136
return match ($key) {
@@ -303,9 +311,14 @@ public function isRDN(): bool
303311
*/
304312
public function render(bool $edit=FALSE,bool $old=FALSE,bool $new=FALSE): View
305313
{
306-
$view = view()->exists($x='components.attribute.'.$this->name_lc)
307-
? view($x)
308-
: view('components.attribute');
314+
$view = match ($this->schema->syntax_oid) {
315+
self::SYNTAX_CERTIFICATE => view('components.syntax.certificate'),
316+
self::SYNTAX_CERTIFICATE_LIST => view('components.syntax.certificatelist'),
317+
318+
default => view()->exists($x = 'components.attribute.' . $this->name_lc)
319+
? view($x)
320+
: view('components.attribute'),
321+
};
309322

310323
return $view
311324
->with('o',$this)
@@ -316,7 +329,12 @@ public function render(bool $edit=FALSE,bool $old=FALSE,bool $new=FALSE): View
316329

317330
public function render_item_old(string $dotkey): ?string
318331
{
319-
return Arr::get($this->values_old->dot(),$dotkey);
332+
return match ($this->schema->syntax_oid) {
333+
self::SYNTAX_CERTIFICATE => join("\n",str_split(base64_encode(Arr::get($this->values_old->dot(),$dotkey)),80)),
334+
self::SYNTAX_CERTIFICATE_LIST => join("\n",str_split(base64_encode(Arr::get($this->values_old->dot(),$dotkey)),80)),
335+
336+
default => Arr::get($this->values_old->dot(),$dotkey),
337+
};
320338
}
321339

322340
public function render_item_new(string $dotkey): ?string

app/Classes/LDAP/Attribute/UserCertificate.php renamed to app/Classes/LDAP/Attribute/Certificate.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
/**
1212
* Represents an attribute whose values is a binary user certificate
1313
*/
14-
final class UserCertificate extends Attribute
14+
final class Certificate extends Attribute
1515
{
1616
use MD5Updates;
1717

@@ -38,11 +38,6 @@ public function expires($key=0): Carbon
3838
return Carbon::createFromTimestampUTC($this->cert_info('validTo_time_t',$key));
3939
}
4040

41-
public function render_item_old(string $dotkey): ?string
42-
{
43-
return join("\n",str_split(base64_encode(parent::render_item_old($dotkey)),80));
44-
}
45-
4641
public function subject($key=0): string
4742
{
4843
$subject = collect($this->cert_info('subject',$key))->reverse();
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace App\Classes\LDAP\Attribute;
4+
5+
use Carbon\Carbon;
6+
use Illuminate\Support\Arr;
7+
8+
use App\Classes\LDAP\Attribute;
9+
use App\Traits\MD5Updates;
10+
11+
/**
12+
* Represents an attribute whose values is a binary user certificate
13+
*/
14+
final class CertificateList extends Attribute
15+
{
16+
use MD5Updates;
17+
}

app/Classes/LDAP/Attribute/Factory.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ class Factory
2020
* Map of attributes to appropriate class
2121
*/
2222
public const map = [
23+
'authorityrevocationlist' => CertificateList::class,
24+
'cacertificate' => Certificate::class,
25+
'certificaterevocationlist' => CertificateList::class,
2326
'createtimestamp' => Internal\Timestamp::class,
2427
'creatorsname' => Internal\DN::class,
2528
'configcontext' => Schema\Generic::class,
@@ -52,7 +55,7 @@ class Factory
5255
'supportedfeatures' => Schema\OID::class,
5356
'supportedldapversion' => Schema\Generic::class,
5457
'supportedsaslmechanisms' => Schema\Mechanisms::class,
55-
'usercertificate' => UserCertificate::class,
58+
'usercertificate' => Certificate::class,
5659
'userpassword' => Password::class,
5760
];
5861

public/js/custom.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,10 @@ function getNode(item) {
4444
location.reload();
4545
break;
4646
case 500:
47+
case 555: // Missing Method
4748
$('.main-content').empty().append(e.responseText);
4849
break;
50+
4951
default:
5052
alert('Well that didnt work? Code ['+e.status+']');
5153
}

resources/views/components/attribute/widget/options.blade.php

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,29 @@
1+
@use(App\Classes\LDAP\Attribute\Certificate)
2+
@use(App\Classes\LDAP\Attribute\CertificateList)
13
@use(App\Classes\LDAP\Attribute\Binary\JpegPhoto)
24
@use(App\Classes\LDAP\Attribute\ObjectClass)
3-
@use(App\Classes\LDAP\Attribute\UserCertificate)
45
@php($clone=FALSE)
56
<span class="p-0 m-0">
67
@if($o->is_rdn)
78
<button class="btn btn-sm btn-outline-focus mt-3" disabled><i class="fas fa-fw fa-exchange"></i> @lang('Rename')</button>
89
@elseif($edit && $o->can_addvalues)
910
@switch(get_class($o))
11+
@case(Certificate::class)
12+
@case(CertificateList::class)
13+
<span @class(['btn','btn-sm','btn-outline-primary','mt-3','addable','d-none'=>(! $new)]) id="{{ $o->name }}-replace" disabled><i class="fas fa-fw fa-certificate"></i> @lang('Replace')</span>
14+
@section('page-scripts')
15+
<script type="text/javascript">
16+
$(document).ready(function() {
17+
$('#{{ $o->name }}-replace.addable').click(function(e) {
18+
alert('Sorry, not implemented yet');
19+
e.preventDefault();
20+
return false;
21+
});
22+
});
23+
</script>
24+
@append
25+
@break
26+
1027
@case(ObjectClass::class)
1128
<span type="button" @class(['btn','btn-sm','btn-outline-primary','mt-3','addable','d-none'=>(! $new)]) data-bs-toggle="modal" data-bs-target="#new_objectclass-modal"><i class="fas fa-fw fa-plus"></i> @lang('Add Objectclass')</span>
1229

@@ -230,21 +247,6 @@ function process_oc() {
230247
@append
231248
@break
232249

233-
@case(UserCertificate::class)
234-
<span @class(['btn','btn-sm','btn-outline-primary','mt-3','addable','d-none'=>(! $new)]) id="{{ $o->name }}-replace" disabled><i class="fas fa-fw fa-certificate"></i> @lang('Replace Certificate')</span>
235-
@section('page-scripts')
236-
<script type="text/javascript">
237-
$(document).ready(function() {
238-
$('#{{ $o->name }}-replace.addable').click(function(e) {
239-
alert('Sorry, not implemented yet');
240-
e.preventDefault();
241-
return false;
242-
});
243-
});
244-
</script>
245-
@append
246-
@break
247-
248250
<!-- All other attributes -->
249251
@default
250252
@if($o->isDynamic()) @break @endif

resources/views/components/attribute/usercertificate.blade.php renamed to resources/views/components/syntax/certificate.blade.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
<!-- $o=UserCertificate::class -->
1+
@use(App\Classes\LDAP\Attribute\Certificate)
2+
3+
<!-- $o=Certificate::class -->
24
<x-attribute.layout :edit="$edit" :new="$new" :o="$o" langtag="binary">
35
@foreach($o->tagValuesOld('binary') as $key => $value)
4-
@if($edit)
6+
<!-- If this attribute is not handle, it'll be an Attribute::class, we'll just render it normally -->
7+
@if(($o instanceof Certificate) && $edit)
58
<input type="hidden" name="name={{ $o->name_lc }}[binary][]" value="{{ md5($value) }}">
69

710
<div class="input-group has-validation mb-3">
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<!-- $o=CertificateList::class -->
2+
<x-attribute.layout :edit="$edit" :new="$new" :o="$o" langtag="binary">
3+
@foreach($o->tagValuesOld('binary') as $key => $value)
4+
<!-- If this attribute is not handle, it'll be an Attribute::class, we'll just render it normally -->
5+
<span class="form-control mb-1"><pre class="m-0">{{ $o->render_item_old('binary.'.$key) }}</pre></span>
6+
@endforeach
7+
</x-attribute.layout>

0 commit comments

Comments
 (0)