~ubuntu-branches/ubuntu/precise/networkmanagement/precise

« back to all changes in this revision

Viewing changes to libs/internals/settings/802-1x.h

  • Committer: Bazaar Package Importer
  • Author(s): Felix Geyer
  • Date: 2011-10-23 14:00:13 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20111023140013-e38hdzybcg6zndrk
Tags: 0.9~svngit.nm09.20111023.ff842e-0ubuntu1
* New upstream snapshot.
* Drop all patches, merged upstream.
* Add kubuntu_add_subdirectory_po.diff to build the translations.

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
#define KNM_SECURITY8021XSETTING_H
5
5
 
6
6
#include <QFile>
7
 
#include <QFlags>
8
7
#include <kglobal.h>
9
8
#include <kdebug.h>
10
9
#include <kcoreconfigskeleton.h>
11
10
#include "setting.h"
12
 
#include "connection.h"
13
11
#include "knminternals_export.h"
14
12
namespace Knm {
15
13
 
16
14
class KNMINTERNALS_EXPORT Security8021xSetting : public Setting
17
15
{
18
 
  Q_FLAGS(Certificates)
19
16
  public:
20
17
    class EnumPhase1peapver
21
18
    {
30
27
    class EnumPhase2auth
31
28
    {
32
29
      public:
33
 
      enum type { none, pap, mschap, mschapv2, chap, md5, gtc, otp, COUNT };
 
30
      enum type { none, pap, mschap, mschapv2, chap, md5, gtc, otp, tls, COUNT };
34
31
    };
35
32
    class EnumPhase2autheap
36
33
    {
42
39
    Security8021xSetting(Security8021xSetting *);
43
40
    ~Security8021xSetting();
44
41
 
45
 
    enum Certificate {CACert = 0x1, ClientCert = 0x2, Phase2CACert = 0x4, Phase2ClientCert = 0x8, PrivateKey = 0x10, Phase2PrivateKey = 0x20};
46
 
    Q_DECLARE_FLAGS(Certificates, Certificate)
47
 
 
48
42
    QString name() const;
49
43
 
50
 
    bool hasSecrets() const;
51
 
 
52
 
    void setSecrets(Setting::secretsTypes);
 
44
    QMap<QString,QString> secretsToMap() const;
 
45
    void secretsFromMap(QMap<QString,QString> secrets);
 
46
    QStringList needSecrets() const;
 
47
    bool hasPersistentSecrets() const;
53
48
 
54
49
    /**
55
50
      Set EAP
107
102
        mCacert = v;
108
103
    }
109
104
 
 
105
    void setCacert( const QString & v)
 
106
    {
 
107
        mCacert = certPathAsByteArray(v);
 
108
    }
 
109
 
110
110
    /**
111
111
      Get CA Cert
112
112
    */
115
115
      return mCacert;
116
116
    }
117
117
 
 
118
    QString cacertasstring()
 
119
    {
 
120
        return certPathAsString(mCacert);
 
121
    }
 
122
 
118
123
    /**
119
124
      Set CA Path
120
125
    */
131
136
      return mCapath;
132
137
    }
133
138
 
134
 
    void setCacertFromPath( const QString & v )
135
 
    {
136
 
        setCapath(v);
137
 
        setCacert(getBytes(v));
138
 
    }
139
 
 
140
 
    /**
141
 
    Get CA Cert to import
142
 
    */
143
 
    QString cacerttoimport() const
144
 
    {
145
 
        return mCacertToImport;
146
 
    }
147
 
 
148
 
    /**
149
 
    Set CA Cert to import
150
 
    */
151
 
    void setCacerttoimport( const QString & v )
152
 
    {
153
 
        mCacertToImport = v;
 
139
    /**
 
140
      Set subject match
 
141
    */
 
142
    void setSubjectmatch( const QString & s)
 
143
    {
 
144
        mSubjectmatch = s;
 
145
    }
 
146
 
 
147
    /**
 
148
      Get subject match
 
149
    */
 
150
    QString subjectmatch() const
 
151
    {
 
152
        return mSubjectmatch;
 
153
    }
 
154
 
 
155
    /**
 
156
      set altsubject matches
 
157
    */
 
158
    void setAltsubjectmatches( const QStringList & v)
 
159
    {
 
160
        mAltsubjectmatches = v;
 
161
    }
 
162
 
 
163
    /**
 
164
      add altsubject match
 
165
    */
 
166
    void addAltsubjectmatch( const QString & s)
 
167
    {
 
168
        if (!mAltsubjectmatches.contains(s))
 
169
            mAltsubjectmatches.append(s);
 
170
    }
 
171
 
 
172
    /**
 
173
      get altsubject matches
 
174
    */
 
175
    QStringList altsubjectmatches() const
 
176
    {
 
177
        return mAltsubjectmatches;
154
178
    }
155
179
 
156
180
    /**
161
185
        mClientcert = v;
162
186
    }
163
187
 
 
188
    void setClientcert( const QString & v )
 
189
    {
 
190
        mClientcert = certPathAsByteArray(v);
 
191
    }
 
192
 
164
193
    /**
165
194
      Get Client Cert
166
195
    */
169
198
      return mClientcert;
170
199
    }
171
200
 
 
201
    QString clientcertasstring()
 
202
    {
 
203
        return certPathAsString(mClientcert);
 
204
    }
 
205
 
172
206
    /**
173
207
      Set Client Cert Path
174
208
    */
185
219
      return mClientcertpath;
186
220
    }
187
221
 
188
 
    void setClientcertFromPath( const QString & v )
189
 
    {
190
 
        setClientcertpath(v);
191
 
        setClientcert(getBytes(v));
192
 
    }
193
 
 
194
 
    /**
195
 
    Get client Cert to import
196
 
    */
197
 
    QString clientcerttoimport() const
198
 
    {
199
 
        return mClientcertToImport;
200
 
    }
201
 
 
202
 
    /**
203
 
    Set client Cert to import
204
 
    */
205
 
    void setClientcerttoimport( const QString & v )
206
 
    {
207
 
        mClientcertToImport = v;
208
 
    }
209
 
 
210
222
    /**
211
223
      Set Phase 1 PEAP version
212
224
    */
295
307
        mPhase2cacert = v;
296
308
    }
297
309
 
 
310
    void setPhase2cacert( const QString & v )
 
311
    {
 
312
        mPhase2cacert = certPathAsByteArray(v);
 
313
    }
 
314
 
298
315
    /**
299
316
      Get Phase 2 CA Cert
300
317
    */
303
320
      return mPhase2cacert;
304
321
    }
305
322
 
 
323
    QString phase2cacertasstring()
 
324
    {
 
325
        return certPathAsString(mPhase2cacert);
 
326
    }
 
327
 
306
328
    /**
307
329
      Set Phase 2 CA Path
308
330
    */
319
341
      return mPhase2capath;
320
342
    }
321
343
 
322
 
    void setPhase2cacertFromPath( const QString & v)
323
 
    {
324
 
        setPhase2capath(v);
325
 
        setPhase2cacert(getBytes(v));
326
 
    }
327
 
 
328
 
    /**
329
 
    Get Phase2CA Cert to import
330
 
    */
331
 
    QString phase2cacerttoimport() const
332
 
    {
333
 
        return mPhase2cacertToImport;
334
 
    }
335
 
 
336
 
    /**
337
 
    Set Phase2CA Cert to import
338
 
    */
339
 
    void setPhase2cacerttoimport( const QString & v )
340
 
    {
341
 
        mPhase2cacertToImport = v;
 
344
    /**
 
345
      Set Phase 2 subject match
 
346
    */
 
347
    void setPhase2subjectmatch( const QString & s)
 
348
    {
 
349
        mPhase2subjectmatch = s;
 
350
    }
 
351
 
 
352
    /**
 
353
      Get Phase 2 subject match
 
354
    */
 
355
    QString phase2subjectmatch() const
 
356
    {
 
357
        return mPhase2subjectmatch;
 
358
    }
 
359
 
 
360
    /**
 
361
      set Phase 2 altsubject matches
 
362
    */
 
363
    void setPhase2altsubjectmatches( const QStringList & v)
 
364
    {
 
365
        mPhase2altsubjectmatches = v;
 
366
    }
 
367
 
 
368
    /**
 
369
      add Phase 2 altsubject match
 
370
    */
 
371
    void addPhase2altsubjectmatch( const QString & s)
 
372
    {
 
373
        if (!mPhase2altsubjectmatches.contains(s))
 
374
            mPhase2altsubjectmatches.append(s);
 
375
    }
 
376
 
 
377
    /**
 
378
      get Phase 2 altsubject matches
 
379
    */
 
380
    QStringList phase2altsubjectmatches() const
 
381
    {
 
382
        return mPhase2altsubjectmatches;
342
383
    }
343
384
 
344
385
    /**
349
390
        mPhase2clientcert = v;
350
391
    }
351
392
 
 
393
    void setPhase2clientcert( const QString & v )
 
394
    {
 
395
        mPhase2clientcert = certPathAsByteArray(v);
 
396
    }
 
397
 
352
398
    /**
353
399
      Get Phase 2 client cert
354
400
    */
357
403
      return mPhase2clientcert;
358
404
    }
359
405
 
 
406
    QString phase2clientcertasstring()
 
407
    {
 
408
        return certPathAsString(mPhase2clientcert);
 
409
    }
 
410
 
360
411
    /**
361
412
      Set Phase 2 client cert path
362
413
    */
373
424
      return mPhase2clientcertpath;
374
425
    }
375
426
 
376
 
    void setPhase2clientcertFromPath( const QString & v)
377
 
    {
378
 
        setPhase2clientcertpath(v);
379
 
        setPhase2clientcert(getBytes(v));
380
 
    }
381
 
 
382
 
    /**
383
 
    Get Phase2 client Cert to import
384
 
    */
385
 
    QString phase2clientcerttoimport() const
386
 
    {
387
 
        return mPhase2clientcertToImport;
388
 
    }
389
 
 
390
 
    /**
391
 
    Set Phase2 client Cert to import
392
 
    */
393
 
    void setPhase2clientcerttoimport( const QString & v )
394
 
    {
395
 
        mPhase2clientcertToImport = v;
396
 
    }
397
 
 
398
427
    /**
399
428
      Set Password
400
429
    */
422
451
    /**
423
452
     * Get Password flags
424
453
     */
425
 
    Setting::secretsTypes passwordflags()
 
454
    Setting::secretsTypes passwordflags() const
426
455
    {
427
456
        return mPasswordflags;
428
457
    }
435
464
        mPrivatekey = v;
436
465
    }
437
466
 
 
467
    void setPrivatekey( const QString & v)
 
468
    {
 
469
        mPrivatekey = certPathAsByteArray(v);
 
470
    }
 
471
 
438
472
    /**
439
473
      Get Private key
440
474
    */
443
477
      return mPrivatekey;
444
478
    }
445
479
 
 
480
    QString privatekeyasstring()
 
481
    {
 
482
        return certPathAsString(mPrivatekey);
 
483
    }
 
484
 
446
485
    /**
447
486
      Set Private key Path
448
487
    */
459
498
      return mPrivatekeypath;
460
499
    }
461
500
 
462
 
    void setPrivatekeyFromPath( const QString & v )
463
 
    {
464
 
        setPrivatekeypath(v);
465
 
        setPrivatekey(getBytes(v));
466
 
    }
467
 
 
468
 
    /**
469
 
    Get private key to import
470
 
    */
471
 
    QString privatekeytoimport() const
472
 
    {
473
 
        return mPrivatekeyToImport;
474
 
    }
475
 
 
476
 
    /**
477
 
    Set private key to import
478
 
    */
479
 
    void setPrivatekeytoimport( const QString & v )
480
 
    {
481
 
        mPrivatekeyToImport = v;
482
 
    }
483
 
 
484
501
    /**
485
502
      Set Private key password
486
503
    */
508
525
    /**
509
526
     * Get Private key password flags
510
527
     */
511
 
    Setting::secretsTypes privatekeypasswordflags()
 
528
    Setting::secretsTypes privatekeypasswordflags() const
512
529
    {
513
530
        return mPrivatekeypasswordflags;
514
531
    }
521
538
        mPhase2privatekey = v;
522
539
    }
523
540
 
 
541
    void setPhase2privatekey( const QString & v)
 
542
    {
 
543
        mPhase2privatekey = certPathAsByteArray(v);
 
544
    }
 
545
 
524
546
    /**
525
547
      Get Phase 2 private key
526
548
    */
529
551
      return mPhase2privatekey;
530
552
    }
531
553
 
 
554
    QString phase2privatekeyasstring()
 
555
    {
 
556
        return certPathAsString(mPhase2privatekey);
 
557
    }
 
558
 
532
559
    /**
533
560
      Set Phase 2 Private key Path
534
561
    */
535
562
    void setPhase2privatekeypath( const QString & v )
536
563
    {
537
564
        mPhase2privatekeypath = v;
 
565
        setPhase2privatekey( getBytes(v));
538
566
    }
539
567
 
540
568
    /**
545
573
      return mPhase2privatekeypath;
546
574
    }
547
575
 
548
 
    void setPhase2privatekeyFromPath( const QString & v )
549
 
    {
550
 
        setPhase2privatekeypath(v);
551
 
        setPhase2privatekey(getBytes(v));
552
 
    }
553
 
 
554
 
    /**
555
 
    Get Phase2private key to import
556
 
    */
557
 
    QString phase2privatekeytoimport() const
558
 
    {
559
 
        return mPhase2privatekeyToImport;
560
 
    }
561
 
 
562
 
    /**
563
 
    Set Phase2private key to import
564
 
    */
565
 
    void setPhase2privatekeytoimport( const QString & v )
566
 
    {
567
 
        mPhase2privatekeyToImport = v;
568
 
    }
569
 
 
570
576
    /**
571
577
      Set Phase 2 private key password
572
578
    */
594
600
    /**
595
601
     * Get Phase 2 private key password flags
596
602
     */
597
 
    Setting::secretsTypes phase2privatekeypasswordflags()
 
603
    Setting::secretsTypes phase2privatekeypasswordflags() const
598
604
    {
599
605
        return mPhase2privatekeypasswordflags;
600
606
    }
601
607
 
602
608
    /**
603
 
      Set PIN
604
 
    */
 
609
     * Set PIN
 
610
     */
605
611
    void setPin( const QString & v )
606
612
    {
607
613
        mPin = v;
608
614
    }
609
615
 
610
616
    /**
611
 
      Get PIN
612
 
    */
 
617
     * Get PIN
 
618
     */
613
619
    QString pin() const
614
620
    {
615
 
      return mPin;
 
621
        return mPin;
616
622
    }
617
623
 
618
624
    /**
626
632
    /**
627
633
     * Get PIN flags
628
634
     */
629
 
    Setting::secretsTypes pinflags()
 
635
    Setting::secretsTypes pinflags() const
630
636
    {
631
637
        return mPinflags;
632
638
    }
653
659
    void setEnabled( bool v )
654
660
    {
655
661
        mEnabled = v;
656
 
        if (!mEnabled)
657
 
            remove();
658
662
    }
659
663
 
660
664
    /**
665
669
      return mEnabled;
666
670
    }
667
671
 
668
 
    /**
669
 
    Get Certs to delete
670
 
    */
671
 
    Certificates certtodelete() const
672
 
    {
673
 
        return mCertificatesToDelete;
674
 
    }
675
 
 
676
 
    /**
677
 
    Add to Certificates to delete
678
 
    */
679
 
    void addToCertToDelete( Certificates v )
680
 
    {
681
 
        mCertificatesToDelete |= v;
682
 
    }
683
 
 
684
 
    /**
685
 
    Remove Certificates to delete
686
 
    */
687
 
    void removeFromCertToDelete( Certificate v )
688
 
    {
689
 
        mCertificatesToDelete &= !v;
690
 
    }
691
 
 
692
 
    QString pathFromCert(const QByteArray & cert)
693
 
    {
694
 
        int len =  cert.size() - 7;
695
 
        if (len < 0)
 
672
    QByteArray certPathAsByteArray(const QString & path)
 
673
    {
 
674
        if (!path.isEmpty()) {
 
675
            QByteArray arr = QByteArray("file://" + path.toUtf8());
 
676
            arr.append('\0');
 
677
            return arr;
 
678
        }
 
679
        else {
 
680
            return QByteArray();
 
681
        }
 
682
    }
 
683
 
 
684
    QString certPathAsString(const QByteArray & path)
 
685
    {
 
686
        if (path.startsWith("file://"))
 
687
            return QString(path.mid(7));
 
688
        else
696
689
            return QString();
697
 
        QString path = QString(cert.right(len));
698
 
        return path;
699
 
    }
700
 
 
701
 
    QByteArray certPathAsByteArray(const QString & path)
702
 
    {
703
 
        QByteArray arr = QByteArray("file://" + path.toUtf8());
704
 
        arr.append('\0');
705
 
        return arr;
706
690
    }
707
691
 
708
692
    enum EapMethod
744
728
        return eapFlags;
745
729
    }
746
730
 
747
 
    QString importCertFromPath( const QString & oldpath, const QString & newpath = QString(), bool scope = true );
748
 
    void save(bool scope);
749
 
    void remove();
750
 
 
751
731
  protected:
752
732
 
753
733
    // 802-1x
756
736
    QString mAnonymousidentity;
757
737
    QByteArray mCacert;
758
738
    QString mCapath;
759
 
    QString mCacertToImport;
 
739
    QString mSubjectmatch;
 
740
    QStringList mAltsubjectmatches;
760
741
    QByteArray mClientcert;
761
742
    QString mClientcertpath;
762
 
    QString mClientcertToImport;
763
743
    int mPhase1peapver;
764
744
    QString mPhase1peaplabel;
765
745
    QString mPhase1fastprovisioning;
767
747
    int mPhase2autheap;
768
748
    QByteArray mPhase2cacert;
769
749
    QString mPhase2capath;
770
 
    QString mPhase2cacertToImport;
 
750
    QString mPhase2subjectmatch;
 
751
    QStringList mPhase2altsubjectmatches;
771
752
    QByteArray mPhase2clientcert;
772
753
    QString mPhase2clientcertpath;
773
 
    QString mPhase2clientcertToImport;
774
754
    QString mPassword;
775
755
    QByteArray mPrivatekey;
776
756
    QString mPrivatekeypath;
777
 
    QString mPrivatekeyToImport;
778
757
    QString mPrivatekeypassword;
779
758
    QByteArray mPhase2privatekey;
780
759
    QString mPhase2privatekeypath;
781
 
    QString mPhase2privatekeyToImport;
782
760
    QString mPhase2privatekeypassword;
783
761
    QString mPin;
784
762
    bool mEnabled;
785
763
    bool mUseSystemCaCerts;
786
 
    Certificates mCertificatesToDelete;
787
764
    Setting::secretsTypes mPasswordflags;
788
765
    Setting::secretsTypes mPrivatekeypasswordflags;
789
766
    Setting::secretsTypes mPhase2privatekeypasswordflags;
790
767
    Setting::secretsTypes mPinflags;
791
768
 
792
769
  private:
793
 
    static const QString CERTIFICATE_PERSISTENCE_PATH;
794
770
    QByteArray getBytes(const QString & fileName);
795
771
};
796
772