Khái quát về Database Auditing - Kimchidhcn's Blog



?N T?P CU?I K?C?C L?NH T?O USER, PH?N QUY?N, H?Y QUY?NGI?M S?TKhái quát v? Database Auditing??nh ngh?a:Auditing là ho?t ??ng giám sát và ghi l?i…. ???c d?a trên các ho?t ??ng cá nh?n nh? th?c hi?n c?u l?nh SQL, hay d?a trên s? k?t h?p các y?u t? bao g?m tên, ?ng d?ng, th?i gian,…Các chính sách b?o m?t có th? d?n ??n vi?c audit khi nh?ng ph?n t? c? th? trong CSDL Oracle b? truy c?p hay thay th?.Auditing nhìn chung ???c s? d?ng:Cho phép gi?i trình nh?ng hành ??ng hi?n t?i tham gia vào m?t schema, b?ng, dòng riêng bi?t, hay m?t n?i dung c? th? nào ?ó.Ng?n c?n user kh?i hành ??ng kh?ng thích h?p d?a trên trách nhi?m ph?i gi?i trình ?ó.?i?u tra các ho?t ??ng ?áng ng?. Ví d?, n?u m?t user kh?ng ???c phép ?ang xóa d? li?u t? m?t b?ng nào ?ó thì ng??i qu?n tr? b?o m?t s? ghi l?i t?t c? nh?ng k?t n?i CDSL và t?t c? nh?ng hành ??ng xóa các dòng t? b?ng trong CSDL dù thành c?ng hay kh?ng thành c?ng.Th?ng báo cho ng??i giám sát r?ng có user b?t h?p phát ?ang thao tác hay xóa d? li?u hay user có nhi?u quy?n h? th?ng h?n s? cho phép.Giám sát và thu th?p d? li?u v? các ho?t ??ng CSDL c? th?. Ví d?, ng??i qu?n tr? CSDL có th? thu th?p th?ng kê v? th?ng tin các b?ng ?ang ???c update, hay bao nhiêu users cùng trung c?p vào th?i ?i?m c?c ??nh.Các ki?u giám sát (Types of Auditing)Oracle cho phép giám sát theo 2 l?a ch?n t?p trung ho?c m? r?ng.S? th?c thi c?u l?nh thành c?ng, ho?c kh?ng thành c?ng, ho?c c? hai.M?i l?n th?c thi c?u l?nh trong m?i session c?a user, hay b?t kì khi nào mà c?u l?nh ???c th?c thi.Ho?t ??ng c?a t?t c? các user hay c?a m?t user c? th? nào ?ó.Có b?n ki?u giám sát:Statement auditing: chia thành hai nhómC?u l?nh DDL: Ví d? AUDIT TABLE giám sát t?t c? các c?u l?nh CREATE và DROP TABLE.C?u l?nh DML: Ví d? AUDIT SELECT TABLE giám sát t?t c? c?u l?nh SELECT trên b?ng và trên viewPrivilege auditing: Ki?m tra vi?c s? d?ng quy?n h? th?ng, ví d? AUDIT CREATE TABLE. Privilege auditing ???c chú tr?ng h?n statement auditing vì nó ch? ki?m tra vi?c s? d?ng m?t s? quy?n nh?t ??nh. Có th? ??t privilege auditing giám sát nh?ng user ???c l?a ch?n hay giám sát m?i user.Schema object auditing: Ki?m tra c?u l?nh c? th? trên ??i t??ng schema c? th?, ví d? AUDIT SELECT ON employees. (R?t ???c chú tr?ng). Schema object auditing lu?n áp d?ng cho t?t c? các user.Fine-grained auditing: Ki?m tra d? li?u truy xu?t và các ho?t ??ng d?a trên n?i dung c?a d? li?u ?ó. Ví d?: S? d?ng DBMS_FGA, ng??i qu?n tr? b?o m?t t?o ra m?t chính sách ki?m tra trên m?t b?ng. N?u b?t kì dòng nào tr? v? t? c?u l?nh DML th?a ?i?u ki?n ki?m tra thì m?t m?c v? s? ki?n ki?m tra s? ???c chèn vào trong audit trail.Audit Records và Audit Trails:Nh?ng th?ng tin ???c audit s? ???c l?u trong data dictionary table, g?i là database audit trail, ho?c l?u trong operating system files, g?i là operating system audit trail.B?n ghi Audit (Audit trail records) Ch?a nh?ng lo?i th?ng tin khác nhau, ph? thu?c vào nh?ng s? ki?n ???c giám sát và t?p các l?a ch?n giám sát. Th?ng tin sau ??y ???c bao g?m trong m?i b?n ghi audit:Database user name (DATABASE USER)Operating system login user name (CLIENT USER)Instance number (kh?ng có trong Operation System…)Process identifier Session identifierTerminal identifierName of the schema object accessedOperation performed or attempted (ACTION)Completion code of the operationDate & time stamp in UTC format ( kh?ng có trong Operation System Audit Trail)System privileges used (PRIVILEGE)Chú ?: Audit trail kh?ng l?u th?ng tin v? giá tr? c?a d? li?u dù nó liên quan ??n trong c?u l?nh ???c giám sát. Ví d?, giá tr? d? li?u m?i và giá tr? d? li?u c? c?a hàng ???c update kh?ng ???c l?u l?i khi c?u l?nh UPDATE ???c giám sát. Tuy v?y, ??i v?i ph??ng pháp fine-grained auditing có khác.Operating System Audit TrailOracle cho phép b?n ghi d?u audit (audit trail records) ???c tr?c ti?p ghi vào operating system audit trail n?u h? ?i?u hành t?o m?t audit trail s?n cho Oracle. N?u kh?ng thì b?n audit s? ???c ghi vào file bên ngoài CSDL, v?i ??nh d?ng t??ng t? nh? các file d?u tích Oracle (Oracle trace) khác.Oracle cho phép m?t ho?t ??ng nào ?ó mà lu?n b? giám sát ???c ti?p t?c, th?m chí khi mà operating system audit trail ( hay file h? ?i?u hành ch?a b?n ghi audit) kh?ng ???c phép ghi l?i b?n ghi audit do nó b? ??y. Tuy nhiên, chú ? r?ng c?u hình auditing ?? s? d?ng database audit trail lo?i b? ???c ?i?m y?u này, b?i vì h? CSDL Oracle ng?n ng?a s? ki?n ???c audit kh?i x?y ra n?u audit trail kh?ng th? ti?p nh?n b?n ghi database audit cho c?u l?nh ?ó.Qu?n lí Standard Audit Trail Kích ho?t Standard AuditingB?t c? database user h?p pháp nào c?ng có th? thi?t l?p l?a ch?n giám sát ??i v?i c?u l?nh, quy?n và ??i t??ng b?t c? khi nào. Tuy nhiên h? CSDL Oracle kh?ng sinh th?ng tin audit cho Standart database audit trail tr? khi CSDL giám sát ???c kích ho?t. Ng??i qu?n tr? b?o m?t th??ng có trách nhi?m ?i?u khi?n vi?c giám sát này.Auditing là ch?c n?ng m?c ??nh trong Oracle server. Các tham s? kh?i t?o ban ??u ?nh h??ng ??n hành vi c?a nó có th? ???c xem b?ng cách s? d?ng c?u l?nh.SQL> SHOW PARAMETER AUDITNAME TYPE VALUE-------------------- -------- ----------------------audit_file_dest string C:\ORACLEXE\APP\ORACLE\ ADMIN\XE\ADUMP audit_sys_operations boolean FALSEaudit_trail string NONECh?c n?ng Audit m?c ??nh b? b?t ho?t, nh?ng có th? kích ho?t nó b?ng cách thi?t l?p giá tr? cho tham s? AUDIT_TRAILAUDIT_TRAIL = { none | os | db | db,extended | xml | xml,extended }Trong ?ó:none or false – ch?c n?ng giám sát b? b?t ho?t.db or true – B?t ch?c n?ng giám sát và các b?n ghi giám sát ???c s? ???c l?u trong database audit trail (SYS.AUD$).xml- B?t ch?c n?ng giám sát v?i các b?n ghi giám sát ???c s? ???c l?u nh? file OS có ??nh d?ng XML.os- B?t ch?c n?ng giám sát v?i các b?n ghi giám sát ???c ghi vào operating system audit trail.Tham s? AUDIT_SYS_OPERATIONS dùng ?? kích ho?t hay b?t ho?t giám sát các ho?t ??ng c?a nh?ng user k?t n?i vào h? th?ng v?i quy?n SYSDBA hay SYSOPER, bao g?m user SYS. Khi ?ó t?t c? các b?n ghi giám sát ???c ghi vào OS audit trail.Tham s? AUDIT_FILE_DEST ??c t? ???ng d?n cho audit trail khi các l?a ch?n OS, XML, EXTENDED ???c s? d?ng. Nó c?ng là v? trí l?u các b?n ghi giám sát khi tham s? AUDIT_SYS_OPERATIONS = true?? kích ho?t ch?c n?ng giám sát, làm theo các b??c sauSQL> ALTER SYSTEM SET audit_trail=db SCOPE=SPFILE;System altered.SQL> SHUTDOWNDatabase closed.Database dismounted.ORACLE instance shut down.SQL> STARTUPORACLE instance started.Database mounted.Database opened.SQL>Kích ho?t l?a ch?n Standard Auditing?? s? d?ng l?nh AUDIT thi?t l?p l?a ch?n v? c?u l?nh và quy?n thì b?n nh?t thi?t ph?i có quy?n AUDIT SYSTEM. Còn ?? thi?t l?p các l?a ch?n giám sát ??i t??ng b?n ph?i làm ch? ??i t??ng b? giám sát hay có quy?n AUDIT ANY.L?nh AUDIT thi?t l?p l?a ch?n giám sát c?u l?nh và quy?n có th? bao g?m m?nh ?? BY ?? c? th? danh sách nh?ng user hay application proxy ?? gi?i h?n t?m v?c c?a c?u l?nh và l?a ch?n giám sát quy?n.BY SESSION/ BY ACCESSBY SESSION: Ghi m?t b?n ghi ??n cho t?t c? các c?u l?nh SQL cùng lo?i th?c thi trên cùng nh?ng ??i t??ng schema trong cùng m?t session. Tuy nhiên n?u s? d?ng operating system trail cho theo d?u giám sát (khi ?ó tham s? AUDIT_FILE_DEST ???c gán giá tr? OS), thì CSDL s? vi?t nhi?u m?c vào file theo d?u ngay c? khi b?n s? d?ng m?nh ?? BY SESSION.BY ACCESS:Ghi m?t b?n ghi cho m?i l?n truy xu?t. N?u ??c t? l?a ch?n c?u l?nh hay quy?n h? th?ng mà giám sát c?u l?nh DDL thì CSDL s? t? ??ng giám sát theo BY ACCESS kh?ng quan t?m b?n s? d?ng m?nh ?? BY SESSION hay BY ACCESS. Ngoài ra thì n?u kh?ng ??c t? thì BY SESSION là m?c ??nh.WHENEVER SUCCESSFUL/ WHENEVER NOT SUCCESSFULWHENEVER SUCCESSFUL giám sát nh?ng l?nh thành c?ng.WHENEVER NOT SUCCESSFUL giám sát nh?ng l?nh th?t b?i hay k?t qu? l?i. N?u lo?i b? hai m?nh ?? này thì Oracle c?ng s? ghi l?i s? giám sát kh?ng quan t?m c?u l?nh có thành c?ng hay kh?ng.B?t ho?t l?a ch?n Standard AuditingC?u l?nh NOAUDIT ?? t?t các l?a ch?n giám sát c?a Oracle 10G.M?nh ?? WHENEVER ?? t?t các giám sát ??i v?i các c?u l?nh ???c th?c hi?n thành c?ng hay kh?ng thành c?ng. N?u kh?ng s? d?ng m?nh ?? ?ó thì ch?c n?ng giám sát s? t?t c? ??i v?i tr??ng h?p thành c?ng hay th?t b?i.M?nh ?? BY SESSION/BY ACCESS kh?ng ???c h? tr? trong c?u l?nh NOAUDIT.?i?u khi?n s? phát tri?n và kích c? c?a Standard Audit TrailN?u audit trail ??y d?n t?i kh?ng m?t b?n ghi giám sát nào ???c ghi thêm vào thì nh?ng c?u l?nh AUDIT kh?ng th? th?c thi thành c?ng cho t?i khi audit trail tr?ng tr? l?i. Do ?ó, ng??i qu?n tr? b?o m?t ph?i ?i?u khi?n s? phát tri?n và kích c? c?a audit trail.Khi ch?c n?ng giám sát ???c kích ho?t và các b?n ghi giám sát ???c sinh ra thì dung l??ng c?a audit trail ph? thu?c hai y?u t?:S? l?a ch?n giám sát ???c s? d?ng.T?n s? th?c hi?n các c?u l?nh ???c giám sát.?? ?i?u khi?n s? phát tri?n c?a audit trail, b?n có th? s? d?ng ph??ng pháp:Kích ho?t và b?t ho?t giám sát CSDL. N?u nó ???c kích ho?t thì các b?n ghi giám sát ???c sinh ra và l?u tr? trong audit trail. N?u nó b?t ho?t thì các b?n ghi s? kh?ng ???c sinh ra.Ch?n l?c k? nh?ng l?a ch?n giám sát ???c kích ho?t. N?u nhi?u l?a ch?n giám sát ???c kích ho?t thì nh?ng b?n ghi giám sát kh?ng c?n thi?t có th? làm ??y audit trail.Qu?n lí ch?t kh? n?ng giám sát ??i t??ng. ?i?u ?ó có th? ???c th?c hi?n b?ng hai cách khác nhau:Nhà qu?n tr? b?o m?t làm ch? t?t c? các ??i t??ng và quy?n h? th?ng AUDIT ANY kh?ng b? c?p cho b?t kì m?t user nào khác.T?t c? các ??i t??ng ch?a trong nh?ng schema mà kh?ng t??ng ?ng v?i database user th?c s? (user ?ó kh?ng ???c c?p quy?n CREATE SESSION) và ng??i qu?n tr? b?o m?t là user duy nh?t có quy?n AUDIT ANY.Xóa m?t s? b?n ghi trong audit trail ?? v?a gi?i phóng vùng nh? v?a làm thu?n ti?n cho vi?c qu?n lí audit trail.Ví d?: Xóa toàn b? b?n ghi trong audit trail:DELETE FROM SYS.AUD$;Xóa toàn b? b?n ghi ???c sinh ra do k?t qu? c?a vi?c giám sát b?ng emp:DELETE FROM SYS.AUD$ WHERE obj$name = ‘EMP’;Chú ?: Ch? có user SYS (user có quy?n DELETE ANY TABLE), hay user ???c SYS gán quy?n DELETE trên SYS.AUD$ m?i có th? th?c hi?n nh?ng c?u l?nh trên.Cú phápL? thuy?taudit::=sql_statement_clause::=Chú ?: Oracle khuyên r?ng nên ??c t? l?a ch?n quy?n h? th?ng và c?u l?nh ?? giám sát h?n là nêu chung qua các role ho?c shortcuts.auditing_by_clause::=Giám sát ch? nh?ng c?u l?nh SQL g?i b?i nh?ng user c? th?. N?u kh?ng s? d?ng m?nh ?? này thì Oracle s? giám sát c?u l?nh c?a t?t c? user.schema_object_clause::=Giám sát các ho?t ??ng trên nh?ng ??i t??ng schema.Object_option: ??c t? ho?t ??ng c? th? cho vi?c giám sát. Ví d? nh? ALTER, COMMENT, AUDIT, DELETE, EXECUTE, GRANT, INSERT, READ,…ALL: là m?t shortcut t??ng ?ng v?i t?t c? các object options cho các lo?i ??i t??ng.auditing_on_clause::=auditing_on_clause: ??c t? ??i t??ng schema riêng bi?t ???c giám sát.ON DEFAULT: thi?t l?p nh?ng l?a ch?n ??i t??ng c? th? tr? thành nh?ng l?a ch?n ??i t??ng m?c ??nh cho nh?ng ??i t??ng ???c t?o ra sau ?ó. Sau khi thi?t l?p nh?ng l?a ch?n giám sát m?c ??nh, b?t kì ??i t??ng nào ???c t?o ra sau ?ó thì ???c giám sát t? ??ng v?i nh?ng l?a ch?n ?ó. Nh?ng l?a ch?n giám sát m?c ??nh cho m?t view lu?n là s? k?t h?p c?a l?a ch?n giám sát cho b?ng c? s? c?a view ?ó. Có th? xem l?a ch?n giám sát m?c ??nh hi?n t?i b?ng cách truy v?n ALL_DEF_AUDIT_OPTS.Khi thay ??i l?a ch?n giám sát m?c ??nh, l?a ch?n giám sát cho nh?ng ??i t??ng ???c t?o lúc tr??c v?n gi? nguyên. B?n có th? thay ??i l?a ch?n giám sát cho ??i t??ng ?? t?n t?i ch? b?ng ??t t? ??i t??ng trong m?nh ?? ON c?a c?u l?nh AUDIT.noaudit::=Th?c hànhGiám sát c?u l?nh SQL liên quan ??n ROLEGiám sát t?t c? các c?u l?nh SQL liên quan ??n ROLE (create, alter, drop, set) kh?ng quan t?m c?u l?nh ???c th?c hi?n thành c?ng hay kh?ng:AUDIT ROLE;Giám sát t?t c? c?u l?nh liên quan ??n ROLE mà th?c hi?n thành c?ng:AUDIT ROLE WHENEVER SUCCESSFUL;Giám sát truy v?n và update c?u l?nh SQLGiám sát cho b?t c? c?u l?nh nào truy v?n hay update b?t kì b?ng nào:AUDIT SELECT TABLE, UPDATE TABLE;Giám sát c?u l?nh phát ra b?i user hr và oe mà truy v?n hay update m?t b?ng ho?c view nào ?ó:AUDIT SELECT TABLE, UPDATE TABLEBY hr, oe;Giám sát xóaGiám sát c?u l?nh s? d?ng quy?n h? th?ng DELETE ANY TABLE:AUDIT DELETE ANY TABLE;Giám sát c?u l?nh liên quan t?i DirectoriesGiám sát c?u l?nh s? d?ng quy?n h? th?ng CREATE ANY DIRECTORY:AUDIT CREATE ANY DIRECTORY;Giám sát l?nh CREATE DIRECTORY (và DROP DIRECTORY) mà kh?ng s? d?ng quy?n h? th?ng CREATE DIRECTORY:AUDIT DIRECTORY;Giám sát m?i c?u l?nh ??c file t? ???ng d?n bfile_dir:AUDIT READ ON DIRECTORY bfile_dir;Giám sát truy v?n trên b?ngGiám sát cho m?i c?u SQL truy v?n t?i b?ng employees trong schema hr:AUDIT SELECT ON hr.employees;Giám sát cho m?i c?u truy v?n t?i b?ng employees trong schema hr và k?t qu? ?ó trong CSDL Oracle b? l?i:AUDIT SELECT ON hr.employeesWHENEVER NOT SUCCESSFUL;Giám sát chèn và update trên b?ngGiám sát cho m?i c?u l?nh chèn và update m?t hàng trong b?ng customers c?a schema oe:AUDIT INSERT, UPDATEON oe.customers;Thi?t l?p m?c ??nh cho l?a ch?n giám sát??c t? l?a ch?n giám sát m?c ??nh cho các ??i t??ng ???c t?o ra trong t??ng lai:AUDIT ALTER, GRANT, INSERT, UPDATE, DELETEON DEFAULT;B?t kì ??i t??ng nào ???c t?o ra sau ?ó s? t? ??ng b? giám sát v?i ??c t? ???c l?a ch?n ?ó (trong tr??ng h?p ch?c n?ng giám sát ???c kích ho?t)N?u t?o ra m?t b?ng thì Oracle t? ??ng giám sát các c?u l?nh ALTER, GRANT, INSERT, UPDATE, DELETE liên quan ??n b?ng này.N?u t?o ra m?t view thì Oracle s? t? ??ng giám sát các c?u l?nh GRANT, INSERT, UPDATE, DELETE liên quan ??n view này.N?u t?o ra m?t procedure, package, hay function thì Oracle s? t? ??ng giám sát các c?u l?nh ALTER hay GRANT liên quan ??n nó.T?t giám sátT?t giám sát trên c?u l?nh:NOAUDIT ALL;T?t giám sát trên quy?n:NOAUDIT ALL PRIVILEGES;Chú ?: ?? b?t ho?t giám sát c?u l?nh và quy?n thì ph?i có quy?n h? th?ng AUDIT SYSTEM.T?t giám sát trên ??i t??ng:NOAUDIT DELETE ON emp;NOAUDIT SELECT, INSERT, DELETE ON jward.dept;?? t?t giám sát trên ??i t??ng c? th? thì b?n ph?i là ch? c?a ??i t??ng ?ó. ?? t?t giám sát trên ??i t??ng c?a m?t ??i t??ng thu?c schema c?a user khác hay t?t giám sát m?c ??nh trên ??i t??ng thì b?n ph?i có quy?n h? th?ng AUDIT ANY.Các view c?a Audit TrailCác b?n ghi giám sát ???c l?u trong b?ng AUD$ trong schema c?a SYS. N?i dung c?a nó có th? ???c xem tr?c ti?p ho?c qua các view.SELECT view_nameFROM dba_viewsWHERE view_name LIKE 'DBA%AUDIT%'ORDER BY view_name;VIEW_NAME------------------------------DBA_AUDIT_EXISTSDBA_AUDIT_OBJECTDBA_AUDIT_POLICIESDBA_AUDIT_POLICY_COLUMNSDBA_AUDIT_SESSIONDBA_AUDIT_STATEMENTDBA_AUDIT_TRAILDBA_COMMON_AUDIT_TRAILDBA_FGA_AUDIT_TRAILDBA_OBJ_AUDIT_OPTSDBA_PRIV_AUDIT_OPTSDBA_REPAUDIT_ATTRIBUTEDBA_REPAUDIT_COLUMNDBA_STMT_AUDIT_OPTS14 rows selected.M? H?AEncryptionUSE masterGOCREATE DATABASE EncryptTestgoUSE EncryptTestGOCREATE TABLE TestTable (FirstCol INT, SecondCol VARBINARY(256))go/* Create Database Master Key */CREATE MASTER KEY ENCRYPTIONBY PASSWORD = 'SQLAuthority'GO/* Create Encryption Certificate */CREATE CERTIFICATE EncryptTestCertWITH SUBJECT = 'SQLAuthority'GO/* Create Symmetric Key */CREATE SYMMETRIC KEY TestTableKeyWITH ALGORITHM = TRIPLE_DES ENCRYPTIONBY CERTIFICATE EncryptTestCertGOOPEN SYMMETRIC KEY TestTableKey DECRYPTION BY CERTIFICATE EncryptTestCertGO--UPDATE TestTable--SET EncryptSecondCol = ENCRYPTBYKEY(KEY_GUID('TestTableKey'),SecondCol)--GOINSERT INTO TestTable values(1,ENCRYPTBYKEY(KEY_GUID('TestTableKey'),'Hello'))INSERT INTO TestTable values(2,ENCRYPTBYKEY(KEY_GUID('TestTableKey'),'123456'))INSERT INTO TestTable values(3,ENCRYPTBYKEY(KEY_GUID('TestTableKey'),'gogogo'))goSELECT * FROM TestTableGO/* Decrypt the data of the SecondCol ?*/OPEN SYMMETRIC KEY TestTableKey DECRYPTION BY CERTIFICATE EncryptTestCertSELECT CONVERT(VARCHAR(50),DECRYPTBYKEY(SecondCol)) AS DecryptSecondColFROM TestTableGOCLOSE SYMMETRIC KEY TestTableKeyGOAPRIL 28, 2009?BY?PINAL DAVESQL SERVER – Introduction to SQL Server Encryption and Symmetric Key Encryption Tutorial with?ScriptSQL Server 2005 and SQL Server 2008 provide encryption as a new feature to protect data against hackers’ attacks. Hackers might be able to penetrate the database or tables, but owing to encryption they would not be able to understand the data or make use of it. Nowadays, it has become imperative to encrypt crucial security-related data while storing in the database as well as during transmission across a network between the client and the server.Encryption hierarchy is marked by three-level security. These three levels provide different mechanisms for securing data across networks and local servers. Different levels of hierarchies allow multiple instances of services (e.g., SQL Server Services) to run on one physical server.Windows Level?– Highest Level – Uses Windows DP API for encryptionSQL Server Level?– Moderate Level – Uses Services Master Key for encryptionDatabase Level?– Lower Level – Uses Database Master Key for encryptionThere are two? kinds of keys used in encryption:Symmetric Key?– In Symmetric cryptography system, the sender and the receiver of a message share a single, common key that is used to encrypt and decrypt the message. This is relatively easy to implement, and both the sender and the receiver can encrypt or decrypt the messages.Asymmetric Key?– Asymmetric cryptography, also known as Public-key cryptography, is a system in which the sender and the receiver of a message have a pair of cryptographic keys – a public key and a private key – to encrypt and decrypt the message. This is a relatively complex system where the sender can use his key to encrypt the message but he cannot decrypt it. The receiver, on the other hand, can use his key to decrypt the message but he cannot encrypt it. This intricacy has turned it into a resource-intensive process.Yet another way to encrypt data is through certificates. A public key certificate is a digitally signed statement that binds the value of a public key to the identity of the person, device, or service that holds the corresponding private key. A Certification Authority (CA) issues and signs certifications.?Download complete script here.Please create a sample database that we will be use for testing Encryption. There are two different kinds of encryptions available in SQL Server:Database Level?– This level secures all the data in a database. However, every time data is written or read from database, the whole database needs to be decrypted. This is a very resource-intensive process and not a practical solution.Column (or Row) Level?– This level of encryption is the most preferred method. Here, only columns containing important data should be encrypted; this will result in lower CPU load compared with the whole database level encryption. If a column is used as a primary key or used in comparison clauses (WHERE clauses, JOIN conditions) the database will have to decrypt the whole column to perform operations involving those columns.Let’s go over a simple instance that demonstrates the encryption and the decryption process executed with Symmetric Key and Triple DES encryption algorithm./*?Create?Database??*/USE?masterGOCREATE?DATABASE?EncryptTestON?PRIMARY?(?NAME?=?N'EncryptTest',?FILENAME?=?N'C:\EncryptTest.mdf')LOG?ON?(?NAME?=?N'EncryptTest_log',?FILENAME?=N'C:\EncryptTest_log.ldf')GOFirst, let’s create a sample table and then populate it with sample data. We will now encrypt one of the two columns of the table./*?Create?table?and?insert?data?in?the?table?*/USE?EncryptTestGOCREATE?TABLE?TestTable?(FirstCol?INT,?SecondCol?VARCHAR(50))GOINSERT?INTO?TestTable?(FirstCol,?SecondCol)SELECT?1,'First'UNION?ALLSELECT?2,'Second'UNION?ALLSELECT?3,'Third'UNION?ALLSELECT?4,'Fourth'UNION?ALLSELECT?5,'Fifth'GO/*?Check?the?content?of?the?TestTable?*/USE?EncryptTestGOSELECT?*FROM?TestTableGOThe preceding code will return the result depicted in the subsequent figure.Result of the SQL queryEvery database can have one master key. Database master key is a symmetric key used to protect the private keys of certificates and asymmetric keys present in the database. It uses Triple DES algorithm together with user-provided password to encrypt the keys./*?Create?Database?Master?Key?*/USE?EncryptTestGOCREATE?MASTER?KEY?ENCRYPTIONBY?PASSWORD?=?'SQLAuthority'GOCertificates are used to safeguard encryption keys, which are used to encrypt data in the database. SQL Server 2005 has the capability to generate self-signed X.509 certificates./*?Create?Encryption?Certificate?*/USE?EncryptTestGOCREATE?CERTIFICATE?EncryptTestCertWITH?SUBJECT?=?'SQLAuthority'GOThe symmetric key can be encrypted by using various options such as certificate, password, symmetric key, and asymmetric key. A number of different algorithms can be employed for encrypting key. The supported algorithms are DES, TRIPLE_DES, RC2, RC4, RC4_128, DESX, AES_128, AES_192, and AES_256./*?Create?Symmetric?Key?*/USE?EncryptTestGOCREATE?SYMMETRIC?KEY?TestTableKeyWITH?ALGORITHM?=?TRIPLE_DES?ENCRYPTIONBY?CERTIFICATE?EncryptTestCertGONow add a column of type varbinary to the original table, which will store the encrypted value for the SecondCol./*??Encrypt?Data?using?Key?and?CertificateAdd?Columns?which?will?hold?the?encrypted?data?in?binary?*/USE?EncryptTestGOALTER?TABLE?TestTableADD?EncryptSecondCol?VARBINARY(256)GOBefore the key is used, it needs to be decrypted using the same method that was used for encrypting it. In our example, we have used a certificate for encrypting the key. Because of the same reason, we are using the same certificate for opening the key and making it available for use. Subsequent to opening it and making it available for use, we can use the encryptkey function and store the encrypted values in the database, in the EncryptSecondCol column./*?Update?binary?column?with?encrypted?data?created?by?certificate?and?key?*/USE?EncryptTestGOOPEN?SYMMETRIC?KEY?TestTableKey?DECRYPTIONBY?CERTIFICATE?EncryptTestCertUPDATE?TestTableSET?EncryptSecondCol?=ENCRYPTBYKEY(KEY_GUID('TestTableKey'),SecondCol)GOWe can drop the original SecondCol column, which we have now encrypted in the EncryptSecondCol column. If you do not want to drop the column, you can keep it for future comparison of the data when we decrypt the column./*?DROP?original?column?which?was?encrypted?for?protect?the?data?*/USE?EncryptTestGOALTER?TABLE?TestTableDROP?COLUMN?SecondColGOWe can run a SELECT query on our database and verify if our data in the table is well protected and hackers will not be able to make use of it even if they somehow manage to reach the data./*?Check?the?content?of?the?TestTable?*/USE?EncryptTestGOSELECT?*FROM?TestTableGOResult of the previous SQL queryAuthorized user can use the decryptbykey function to retrieve the original data from the encrypted column. If Symmetric key is not open for decryption, it has to be decrypted using the same certificate that was used to encrypt it. An important point to bear in mind here is that the original column and the decrypted column should have the same data types. If their data types differ, incorrect values could be reproduced. In our case, we have used a VARCHAR data type for SecondCol and EncryptSecondCol./*?Decrypt?the?data?of?the?SecondCol??*/USE?EncryptTestGOOPEN?SYMMETRIC?KEY?TestTableKey?DECRYPTIONBY?CERTIFICATE?EncryptTestCertSELECT?CONVERT(VARCHAR(50),DECRYPTBYKEY(EncryptSecondCol))?ASDecryptSecondColFROM?TestTableGOIf you drop the database after the entire processing is complete, you do not have to worry about cleaning up the database. However, in real world on production servers, the database is not dropped. It is a good practice for developers to close the key after using it. If keys and certificates are used only once or their use is over, they can be dropped as well. Dropping a database will drop everything it contains – table, keys, certificates, all the data, to name a few./*?Clean?up?database??*/USE?EncryptTestGOCLOSE?SYMMETRIC?KEY?TestTableKeyGODROP?SYMMETRIC?KEY?TestTableKeyGODROP?CERTIFICATE?EncryptTestCertGODROP?MASTER?KEYGOUSE?[master]GODROP?DATABASE?[EncryptTest]GOSummaryEncryption is a very important security feature of SQL Server 2005. Long keys and asymmetric keys create unassailable, stronger encryption and stronger encryption uses lots of CPU to encrypt data. Stronger encryption is slower to process. When there is a huge amount of data to encrypt, it is suggested to encrypt it using a symmetric key. The same symmetric key can be encrypted further with an asymmetric key for additional protection, thereby adding the advantage of a stronger encryption. It is also recommended to compress data before encryption, as encrypted data cannot be compressed.CH?NH S?CHBài th?c hành s? 11ORACLE LABEL SECURITY (4)Tóm t?t n?i dung:Che d?u c?t th?ng tin chính sáchS? d?ng hàm gán nh?nCác view c?a OLSM?t s? k? thu?t n?ng cao trong OLSL? thuy?tChe d?u c?t th?ng tin nh?n d? li?u?? tránh vi?c hi?n th? c?t ch?a th?ng tin chính sách, ng??i qu?n tr? có th? thi?t l?p tùy ch?n HIDE khi gán chính sách cho b?ng.M?t khi chính sách ?? ???c áp d?ng, tr?ng thái ?n/Kh?ng ?n c?a c?t kh?ng th? ???c thay ??i tr? khi ta remove chính sách kh?i b?ng v?i tham s? DROP_COLUMN b?ng TRUE. Sau ?ó chính sách có th? ???c áp d?ng l?i v?i tr?ng thái m?i.Khi ng??i dùng INSERT d? li?u vào b?ng có tr?ng thái ?n c?t chính sách, giá tr? c?a c?t ch?a nh?n s? kh?ng b? yêu c?u ph?i insert.C?u l?nh SELECT * s? kh?ng t? ??ng tr? v? giá tr? c?a c?t ?n, tr? khi nó ???c truy xu?t tr?c ti?p.C?u l?nh DESCRIBE c?ng s? kh?ng hi?n th? th?ng tin c?t ?n.Hàm gán nh?nCó nh?ng b?ng d? li?u l?n, ta kh?ng th? ng?i gán nh?n cho t?ng tr??ng h?p. OLS cung c?p cho ta m?t cách gán nh?n khác. ?ó là s? d?ng m?t hàm (function) do mình hi?n th?c ?? OLS s? t? ??ng gán nh?n m?i khi có hàng m?i ???c insert vào b?ng d? li?u ???c b?o v?. Xem ph?n th?c hành ?? hi?u r? h?n v? cách th?c làm vi?c này.Hàm gán nh?n s? override 2 tùy ch?n LABEL_DEFAULT và LABEL_UPDATE.Th?c hànhChe d?u c?t th?ng tin chính sáchDo trong bài lab tr??c, ta ?? áp d?ng chính sách cho b?ng mà kh?ng có tùy ch?n HIDE nên trong b?i lab này ta ph?i remove chính sách (xóa lu?n c?t th?ng tin), th?c hi?n l?i ?o?n code gán nh?n trong bài lab tr??c và gán l?i chính sách.CONN sec_admin/secadmin;BEGINsa_policy_admin.remove_table_policy(policy_name => 'ACCESS_LOCATIONS',schema_name => 'HR',table_name => 'LOCATIONS',drop_column => true);END;/SELECT * FROM hr.locations;Ta nh?n th?y lúc này c?t OLS_COLUMN v?n ch?a b? xóa dù Oracle báo th?c hi?n thành c?ng th? t?c. L? do là khi remove chính sách, ta s? xóa c?t OLS_COLUMN, t?c là ?? thay ??i b?ng Locations. Do v?y ta c?n c?p thêm quy?n ALTER trên b?ng Locations cho sec_admin ?? c?t OLS_COLUMN th?t s? b? xóa. B?y gi? ta gán l?i chính sách trên ?? th?y s? thay ??i sau khi sec_admin ???c gán quy?n.CONN sec_admin/secadmin;BEGINsa_policy_admin.apply_table_policy(policy_name => 'ACCESS_LOCATIONS',schema_name => 'HR',table_name => 'LOCATIONS',table_options => 'NO_CONTROL');END;/CONN system/system;GRANT alter ON hr.locations TO sec_admin;CONN sec_admin/secadmin;BEGINsa_policy_admin.remove_table_policy(policy_name => 'ACCESS_LOCATIONS',schema_name => 'HR',table_name => 'LOCATIONS',drop_column => true);END;/SELECT * FROM hr.locations;Ta nh?n th?y b?y gi? c?t OLS_COLUMN ?? th?t s? ???c xóa.Gán l?i chính sách cho b?ng v?i NO_CONTROL và HIDE:CONN sec_admin/secadmin;BEGINsa_policy_admin.apply_table_policy(policy_name => 'ACCESS_LOCATIONS',schema_name => 'HR',table_name => 'LOCATIONS',table_options => 'HIDE,NO_CONTROL');END;/Gán l?i nh?n cho d? li?u trong b?ng (do lúc remove ?? xóa m?t c?t ch?a th?ng tin chính sách):CONN sec_admin/secadmin;UPDATE hr.locations SET ols_column = char_to_label ('ACCESS_LOCATIONS', 'CONF');UPDATE hr.locations SET ols_column = char_to_label ('ACCESS_LOCATIONS', 'CONF::US')WHERE country_id = 'US';UPDATE hr.locations SET ols_column = char_to_label ('ACCESS_LOCATIONS', 'CONF::UK')WHERE country_id = 'UK';UPDATE hr.locations SET ols_column = char_to_label ('ACCESS_LOCATIONS', 'CONF::CA')WHERE country_id = 'CA';UPDATE hr.locations SET ols_column = char_to_label ('ACCESS_LOCATIONS', 'CONF:SM:UK,CA')WHERE (country_id = 'CA' and city = 'Toronto')or (country_id = 'UK' and city = 'Oxford');UPDATE hr.locations SET ols_column = char_to_label ('ACCESS_LOCATIONS', 'CONF:HR:UK')WHERE country_id = 'UK' and city = 'London';UPDATE hr.locations SET ols_column = char_to_label ('ACCESS_LOCATIONS', 'SENS:HR,SM,FIN:CORP')WHERE country_id = 'CH' and city = 'Geneva';COMMIT ;Ti?p theo ta c?n gán l?i chính sách v?i tùy ch?n HIDE và READ_CONTROL:CONN sec_admin/secadmin;BEGINsa_policy_admin.remove_table_policy(policy_name => 'ACCESS_LOCATIONS',schema_name => 'HR',table_name => 'LOCATIONS');sa_policy_admin.apply_table_policy(policy_name => 'ACCESS_LOCATIONS',schema_name => 'HR',table_name => 'LOCATIONS',table_options=> 'HIDE,READ_CONTROL,WRITE_CONTROL,CHECK_CONTROL');END;/B?y gi? ta th? truy xu?t b?ng Locations:CONN sec_admin/secadmin;SELECT * FROM hr.locations;DESCRIBE hr.locations;K?t qu? c?a dòng code SELECT là “no rows selected”. Ch? có c?u l?nh DESCRIBE có tr? v? k?t qu?. Nguyên nh?n là do b?y gi? b?ng này ?? ???c b?o v?, ch? nh?ng ng??i ???c c?p quy?n OLS c? th? m?i có th? truy xu?t. Ta log in l?i b?ng user SKING:CONN sking/sking;SELECT * FROM hr.locations;SELECT label_to_char (ols_column) as label, locations.*FROM hr.locations;Ta th?y trong c?u l?nh SELECT th? 2, ta có ch? ??nh r? c?t ols_column nên c?t này m?i xu?t hi?n. Trong k?t qu? truy v?n c?a c?u SELECT th? nh?t kh?ng có c?t th?ng tin chính sách này.Dùng hàm gán nh?nTrong ph?n th?c hành này, ta s? dùng b?ng Employees c?a schem HR ?? minh h?a.C?p các quy?n c?n thi?t cho sec_admin trên b?ng Employees:CONN system/system;GRANT select, insert, update, alterON hr.employees TO sec_admin;GRANT create procedure TO sec_admin;CONN lbacsys/lbacsysGRANT execute ON to_lbac_data_label TO sec_admin WITH GRANT OPTION;Ti?p theo ta vi?t m?t hàm gán nh?n d?a trên ?i?u ki?n c?a th?ng tin nh?n viên:CONN sec_admin/secadmin;CREATE OR REPLACE FUNCTION sec_admin.gen_emp_label (Job varchar2, Depto number, Sal number)RETURN LBACSYS.LBAC_LABELAS i_label varchar2(80);BEGIN/************* Xác ??nh level *************/ IF Sal > 17000 THEN i_label := 'SENS:'; ELSIF Sal > 10000 THEN i_label := 'CONF:'; ELSE i_label := 'PUB:'; END IF;/************* Xác ??nh compartment *************/IF Job LIKE '%HR%' THEN i_label := i_label||'HR:';ELSIF (Job LIKE '%MK%') OR (Job LIKE '%SA%') THEN i_label := i_label||'SM:';ELSIF Job LIKE '%FI%' THEN i_label := i_label||'FIN:';ELSE i_label := i_label||':'; END IF;/************* Xác ??nh groups *************/ i_label := i_label||'CORP'; RETURN TO_LBAC_DATA_LABEL('ACCESS_LOCATIONS',i_label);END;/Ta c?n gán cho LBACSYS quy?n th?c thi trên hàm gán nh?n v?a ???c t?o:CONN sec_admin/secadmin;GRANT execute ON sec_admin.gen_emp_label TO lbacsys;Ta ch? ??nh th? t?c v?a hi?n th?c làm hàm gán nh?n cho b?ng Employees:CONN sec_admin/secadmin;BEGINSA_POLICY_ADMIN.APPLY_TABLE_POLICY (policy_name => 'ACCESS_LOCATIONS',schema_name => 'HR',table_name => 'EMPLOYEES',table_options=> 'READ_CONTROL,WRITE_CONTROL,CHECK_CONTROL',label_function=> 'sec_admin.gen_emp_label (:new.job_id,:new.department_id,:new.salary)');END;/Các view th?ng tin c?a OLSCác th?ng tin v? các chính sách c?a OLS ???c l?u trong data dictionary. Ta có th? xem các th?ng tin này th?ng qua các view c?a OLS.View DBA_SA_USERS: hi?n th? th?ng tin v? t?t c? các chính sách có trong CSDL.DBA_SA_USER_LEVELS: hi?n th? th?ng tin level c?a m?i ng??i dùng.DBA_SA_USER_COMPARTMENTS: hi?n th? th?ng tin compartment c?a m?i ng??i dùng.DBA_SA_USER_GROUPS: hi?n th? th?ng tin group c?a m?i ng??i dùng.?? xem t?t c? các view trên c?n log in vào tài kho?n LBACSYS ho?c ???c c?p quy?n SELECT t? LBACSYS.conn lbacsys/lbacsys;select * from DBA_SA_USERS;select * from DBA_SA_USER_LEVELS; select * from DBA_SA_USER_COMPARTMENTS; select * from DBA_SA_USER_GROUPS; Bài t?pVi?t hàm gán nh?n GET_CUSTOMER_LABEL cho các khách hàng trong b?ng CUSTOMERS ?? t?o ? bài lab 9 theo ?i?u ki?n sau:Credit > 2000: level 3; 500 < credit <= 2000: level 2; còn l?i level 1Cust_type = ‘Platinum’ thì compartment là Manager, còn l?i là EmployeeGroup gán theo region.Th?c hi?n các c?u l?nh c?n thi?t ?? b?ng trên ???c gán nh?n và ???c áp d?ng chính sách REGION_POLICY ?? t?o trong bài lab 8.Th?c hi?n m?t s? c?u l?nh ?? ki?m tra tác d?ng c?a chính sách. ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download

To fulfill the demand for quickly locating and searching documents.

It is intelligent file search solution for home and business.

Literature Lottery

Related searches