提交 2bfae6de authored 作者: Thomas Mueller's avatar Thomas Mueller

--no commit message

--no commit message
上级 e4a5e558
......@@ -112,10 +112,13 @@
</target>
<target name="compileServlet" depends="compileServletTest, compile" if="servlet.jar.present">
<javac executable="${javac}" srcdir="src/main" destdir="bin" debug="true">
<javac executable="${javac}" destdir="bin" debug="true">
<src path="src/main"/>
<src path="src/test"/>
<classpath location="${path.servlet.jar}" />
<include name="org/h2/server/web/WebServlet.java"/>
<include name="org/h2/server/web/DbStarter.java"/>
<include name="org/h2/test/unit/TestServlet.java"/>
</javac>
</target>
......@@ -133,6 +136,7 @@
<exclude name="org/h2/fulltext/FullTextLucene.java"/>
<exclude name="org/h2/server/web/WebServlet.java"/>
<exclude name="org/h2/server/web/DbStarter.java"/>
<exclude name="org/h2/test/unit/TestServlet.java"/>
</javac>
<copy todir="bin" overwrite="true">
<fileset dir="src/main" includes="META-INF/**/*"/>
......
......@@ -469,376 +469,379 @@ PG Protocol Support Limitations
@advanced_1156_p
At this time, only a subset of the PostgreSQL network protocol is implemented. Also, there may be compatibility problems on the SQL level, with the catalog, or with text encoding. Problems are fixed as they are found. Currently, statements can not be cancelled when using the PG protocol.
@advanced_1157_h3
@advanced_1157_p
PostgreSQL ODBC Driver Setup requires a database password, that means it is not possible to connect to H2 databases without password. This is a limitation of the ODBC driver.
@advanced_1158_h3
Security Considerations
@advanced_1158_p
@advanced_1159_p
Currently, the PG Server does not support challenge response or encrypt passwords. This may be a problem if an attacker can listen to the data transferred between the ODBC driver and the server, because the password is readable to the attacker. Also, it is currently not possible to use encrypted SSL connections. Therefore the ODBC driver should not be used where security is important.
@advanced_1159_h2
@advanced_1160_h2
ACID
@advanced_1160_p
@advanced_1161_p
In the database world, ACID stands for:
@advanced_1161_li
@advanced_1162_li
Atomicity: Transactions must be atomic, meaning either all tasks are performed or none.
@advanced_1162_li
@advanced_1163_li
Consistency: All operations must comply with the defined constraints.
@advanced_1163_li
@advanced_1164_li
Isolation: Transactions must be isolated from each other.
@advanced_1164_li
@advanced_1165_li
Durability: Committed transaction will not be lost.
@advanced_1165_h3
@advanced_1166_h3
Atomicity
@advanced_1166_p
@advanced_1167_p
Transactions in this database are always atomic.
@advanced_1167_h3
@advanced_1168_h3
Consistency
@advanced_1168_p
@advanced_1169_p
This database is always in a consistent state. Referential integrity rules are always enforced.
@advanced_1169_h3
@advanced_1170_h3
Isolation
@advanced_1170_p
@advanced_1171_p
For H2, as with most other database systems, the default isolation level is 'read committed'. This provides better performance, but also means that transactions are not completely isolated. H2 supports the transaction isolation levels 'serializable', 'read committed', and 'read uncommitted'.
@advanced_1171_h3
@advanced_1172_h3
Durability
@advanced_1172_p
@advanced_1173_p
This database does not guarantee that all committed transactions survive a power failure. Tests show that all databases sometimes lose transactions on power failure (for details, see below). Where losing transactions is not acceptable, a laptop or UPS (uninterruptible power supply) should be used. If durability is required for all possible cases of hardware failure, clustering should be used, such as the H2 clustering mode.
@advanced_1173_h2
@advanced_1174_h2
Durability Problems
@advanced_1174_p
@advanced_1175_p
Complete durability means all committed transaction survive a power failure. Some databases claim they can guarantee durability, but such claims are wrong. A durability test was run against H2, HSQLDB, PostgreSQL, and Derby. All of those databases sometimes lose committed transactions. The test is included in the H2 download, see org.h2.test.poweroff.Test.
@advanced_1175_h3
@advanced_1176_h3
Ways to (Not) Achieve Durability
@advanced_1176_p
@advanced_1177_p
Making sure that committed transaction are not lost is more complicated than it seems first. To guarantee complete durability, a database must ensure that the log record is on the hard drive before the commit call returns. To do that, databases use different methods. One is to use the 'synchronous write' file access mode. In Java, RandomAccessFile supports the modes "rws" and "rwd":
@advanced_1177_li
@advanced_1178_li
rwd: Every update to the file's content is written synchronously to the underlying storage device.
@advanced_1178_li
@advanced_1179_li
rws: In addition to rwd, every update to the metadata is written synchronously.
@advanced_1179_p
@advanced_1180_p
This feature is used by Derby. A test (org.h2.test.poweroff.TestWrite) with one of those modes achieves around 50 thousand write operations per second. Even when the operating system write buffer is disabled, the write rate is around 50 thousand operations per second. This feature does not force changes to disk because it does not flush all buffers. The test updates the same byte in the file again and again. If the hard drive was able to write at this rate, then the disk would need to make at least 50 thousand revolutions per second, or 3 million RPM (revolutions per minute). There are no such hard drives. The hard drive used for the test is about 7200 RPM, or about 120 revolutions per second. There is an overhead, so the maximum write rate must be lower than that.
@advanced_1180_p
@advanced_1181_p
Buffers can be flushed by calling the function fsync. There are two ways to do that in Java:
@advanced_1181_li
@advanced_1182_li
FileDescriptor.sync(). The documentation says that this forces all system buffers to synchronize with the underlying device. Sync is supposed to return after all in-memory modified copies of buffers associated with this FileDescriptor have been written to the physical medium.
@advanced_1182_li
@advanced_1183_li
FileChannel.force() (since JDK 1.4). This method is supposed to force any updates to this channel's file to be written to the storage device that contains it.
@advanced_1183_p
@advanced_1184_p
By default, MySQL calls fsync for each commit. When using one of those methods, only around 60 write operations per second can be achieved, which is consistent with the RPM rate of the hard drive used. Unfortunately, even when calling FileDescriptor.sync() or FileChannel.force(), data is not always persisted to the hard drive, because most hard drives do not obey fsync(): see 'Your Hard Drive Lies to You' at http://hardware.slashdot.org/article.pl?sid=05/05/13/0529252. In Mac OS X fsync does not flush hard drive buffers: http://lists.apple.com/archives/darwin-dev/2005/Feb/msg00072.html. So the situation is confusing, and tests prove there is a problem.
@advanced_1184_p
@advanced_1185_p
Trying to flush hard drive buffers hard, and if you do the performance is very bad. First you need to make sure that the hard drive actually flushes all buffers. Tests show that this can not be done in a reliable way. Then the maximum number of transactions is around 60 per second. Because of those reasons, the default behavior of H2 is to delay writing committed transactions.
@advanced_1185_p
@advanced_1186_p
In H2, after a power failure, a bit more than one second of committed transactions may be lost. To change the behavior, use SET WRITE_DELAY and CHECKPOINT SYNC. Most other databases support commit delay as well. In the performance comparison, commit delay was used for all databases that support it.
@advanced_1186_h3
@advanced_1187_h3
Running the Durability Test
@advanced_1187_p
@advanced_1188_p
To test the durability / non-durability of this and other databases, you can use the test application in the package org.h2.test.poweroff. Two computers with network connection are required to run this test. One computer just listens, while the test application is run (and power is cut) on the other computer. The computer with the listener application opens a TCP/IP port and listens for an incoming connection. The second computer first connects to the listener, and then created the databases and starts inserting records. The connection is set to 'autocommit', which means after each inserted record a commit is performed automatically. Afterwards, the test computer notifies the listener that this record was inserted successfully. The listener computer displays the last inserted record number every 10 seconds. Now, switch off the power manually, then restart the computer, and run the application again. You will find out that in most cases, none of the databases contains all the records that the listener computer knows about. For details, please consult the source code of the listener and test application.
@advanced_1188_h2
@advanced_1189_h2
Using the Recover Tool
@advanced_1189_p
@advanced_1190_p
The recover tool can be used to extract the contents of a data file, even if the database is corrupted. At this time, it does not extract the content of the log file or large objects (CLOB or BLOB). To run the tool, type on the command line:
@advanced_1190_p
@advanced_1191_p
For each database in the current directory, a text file will be created. This file contains raw insert statement (for the data) and data definition (DDL) statement to recreate the schema of the database. This file cannot be executed directly, as the raw insert statements don't have the correct table names, so the file needs to be pre-processed manually before executing.
@advanced_1191_h2
@advanced_1192_h2
File Locking Protocols
@advanced_1192_p
@advanced_1193_p
Whenever a database is opened, a lock file is created to signal other processes that the database is in use. If database is closed, or if the process that opened the database terminates, this lock file is deleted.
@advanced_1193_p
@advanced_1194_p
In special cases (if the process did not terminate normally, for example because there was a blackout), the lock file is not deleted by the process that created it. That means the existence of the lock file is not a safe protocol for file locking. However, this software uses a challenge-response protocol to protect the database files. There are two methods (algorithms) implemented to provide both security (that is, the same database files cannot be opened by two processes at the same time) and simplicity (that is, the lock file does not need to be deleted manually by the user). The two methods are 'file method' and 'socket methods'.
@advanced_1194_h3
@advanced_1195_h3
File Locking Method 'File'
@advanced_1195_p
@advanced_1196_p
The default method for database file locking is the 'File Method'. The algorithm is:
@advanced_1196_li
@advanced_1197_li
When the lock file does not exist, it is created (using the atomic operation File.createNewFile). Then, the process waits a little bit (20ms) and checks the file again. If the file was changed during this time, the operation is aborted. This protects against a race condition when a process deletes the lock file just after one create it, and a third process creates the file again. It does not occur if there are only two writers.
@advanced_1197_li
@advanced_1198_li
If the file can be created, a random number is inserted together with the locking method ('file'). Afterwards, a watchdog thread is started that checks regularly (every second once by default) if the file was deleted or modified by another (challenger) thread / process. Whenever that occurs, the file is overwritten with the old data. The watchdog thread runs with high priority so that a change to the lock file does not get through undetected even if the system is very busy. However, the watchdog thread does use very little resources (CPU time), because it waits most of the time. Also, the watchdog only reads from the hard disk and does not write to it.
@advanced_1198_li
@advanced_1199_li
If the lock file exists, and it was modified in the 20 ms, the process waits for some time (up to 10 times). If it was still changed, an exception is thrown (database is locked). This is done to eliminate race conditions with many concurrent writers. Afterwards, the file is overwritten with a new version (challenge). After that, the thread waits for 2 seconds. If there is a watchdog thread protecting the file, he will overwrite the change and this process will fail to lock the database. However, if there is no watchdog thread, the lock file will still be as written by this thread. In this case, the file is deleted and atomically created again. The watchdog thread is started in this case and the file is locked.
@advanced_1199_p
@advanced_1200_p
This algorithm is tested with over 100 concurrent threads. In some cases, when there are many concurrent threads trying to lock the database, they block each other (meaning the file cannot be locked by any of them) for some time. However, the file never gets locked by two threads at the same time. However using that many concurrent threads / processes is not the common use case. Generally, an application should throw an error to the user if it cannot open a database, and not try again in a (fast) loop.
@advanced_1200_h3
@advanced_1201_h3
File Locking Method 'Socket'
@advanced_1201_p
@advanced_1202_p
There is a second locking mechanism implemented, but disabled by default. The algorithm is:
@advanced_1202_li
@advanced_1203_li
If the lock file does not exist, it is created. Then a server socket is opened on a defined port, and kept open. The port and IP address of the process that opened the database is written into the lock file.
@advanced_1203_li
@advanced_1204_li
If the lock file exists, and the lock method is 'file', then the software switches to the 'file' method.
@advanced_1204_li
@advanced_1205_li
If the lock file exists, and the lock method is 'socket', then the process checks if the port is in use. If the original process is still running, the port is in use and this process throws an exception (database is in use). If the original process died (for example due to a blackout, or abnormal termination of the virtual machine), then the port was released. The new process deletes the lock file and starts again.
@advanced_1205_p
@advanced_1206_p
This method does not require a watchdog thread actively polling (reading) the same file every second. The problem with this method is, if the file is stored on a network share, two processes (running on different computers) could still open the same database files, if they do not have a direct TCP/IP connection.
@advanced_1206_h2
@advanced_1207_h2
Protection against SQL Injection
@advanced_1207_h3
@advanced_1208_h3
What is SQL Injection
@advanced_1208_p
@advanced_1209_p
This database engine provides a solution for the security vulnerability known as 'SQL Injection'. Here is a short description of what SQL injection means. Some applications build SQL statements with embedded user input such as:
@advanced_1209_p
@advanced_1210_p
If this mechanism is used anywhere in the application, and user input is not correctly filtered or encoded, it is possible for a user to inject SQL functionality or statements by using specially built input such as (in this example) this password: ' OR ''='. In this case the statement becomes:
@advanced_1210_p
@advanced_1211_p
Which is always true no matter what the password stored in the database is. For more information about SQL Injection, see Glossary and Links.
@advanced_1211_h3
@advanced_1212_h3
Disabling Literals
@advanced_1212_p
@advanced_1213_p
SQL Injection is not possible if user input is not directly embedded in SQL statements. A simple solution for the problem above is to use a PreparedStatement:
@advanced_1213_p
@advanced_1214_p
This database provides a way to enforce usage of parameters when passing user input to the database. This is done by disabling embedded literals in SQL statements. To do this, execute the statement:
@advanced_1214_p
@advanced_1215_p
Afterwards, SQL statements with text and number literals are not allowed any more. That means, SQL statement of the form WHERE NAME='abc' or WHERE CustomerId=10 will fail. It is still possible to use PreparedStatements and parameters as described above. Also, it is still possible to generate SQL statements dynamically, and use the Statement API, as long as the SQL statements do not include literals. There is also a second mode where number literals are allowed: SET ALLOW_LITERALS NUMBERS. To allow all literals, execute SET ALLOW_LITERALS ALL (this is the default setting). Literals can only be enabled or disabled by an administrator.
@advanced_1215_h3
@advanced_1216_h3
Using Constants
@advanced_1216_p
@advanced_1217_p
Disabling literals also means disabling hard-coded 'constant' literals. This database supports defining constants using the CREATE CONSTANT command. Constants can be defined only when literals are enabled, but used even when literals are disabled. To avoid name clashes with column names, constants can be defined in other schemas:
@advanced_1217_p
@advanced_1218_p
Even when literals are enabled, it is better to use constants instead of hard-coded number or text literals in queries or views. With constants, typos are found at compile time, the source code is easier to understand and change.
@advanced_1218_h3
@advanced_1219_h3
Using the ZERO() Function
@advanced_1219_p
@advanced_1220_p
It is not required to create a constant for the number 0 as there is already a built-in function ZERO():
@advanced_1220_h2
@advanced_1221_h2
Restricting Class Loading and Usage
@advanced_1221_p
@advanced_1222_p
By default there is no restriction on loading classes and executing Java code for admins. That means an admin may call system functions such as System.setProperty by executing:
@advanced_1222_p
@advanced_1223_p
To restrict users (including admins) from loading classes and executing code, the list of allowed classes can be set in the system property h2.allowedClasses in the form of a comma separated list of classes or patterns (items ending with '*'). By default all classes are allowed. Example:
@advanced_1223_p
@advanced_1224_p
This mechanism is used for all user classes, including database event listeners, trigger classes, user defined functions, user defined aggregate functions, and JDBC driver classes (with the exception of the H2 driver) when using the H2 Console.
@advanced_1224_h2
@advanced_1225_h2
Security Protocols
@advanced_1225_p
@advanced_1226_p
The following paragraphs document the security protocols used in this database. These descriptions are very technical and only intended for security experts that already know the underlying security primitives.
@advanced_1226_h3
@advanced_1227_h3
User Password Encryption
@advanced_1227_p
@advanced_1228_p
When a user tries to connect to a database, the combination of user name, @, and password hashed using SHA-256, and this hash value is transmitted to the database. This step does not try to an attacker from re-using the value if he is able to listen to the (unencrypted) transmission between the client and the server. But, the passwords are never transmitted as plain text, even when using an unencrypted connection between client and server. That means if a user reuses the same password for different things, this password is still protected up to some point. See also 'RFC 2617 - HTTP Authentication: Basic and Digest Access Authentication' for more information.
@advanced_1228_p
@advanced_1229_p
When a new database or user is created, a new cryptographically secure random salt value is generated. The size of the salt is 64 bit. Using the random salt reduces the risk of an attacker pre-calculating hash values for many different (commonly used) passwords.
@advanced_1229_p
@advanced_1230_p
The combination of user-password hash value (see above) and salt is hashed using SHA-256. The resulting value is stored in the database. When a user tries to connect to the database, the database combines user-password hash value with the stored salt value and calculated the hash value. Other products use multiple iterations (hash the hash value again and again), but this is not done in this product to reduce the risk of denial of service attacks (where the attacker tries to connect with bogus passwords, and the server spends a lot of time calculating the hash value for each password). The reasoning is: if the attacker has access to the hashed passwords, he also has access to the data in plain text, and therefore does not need the password any more. If the data is protected by storing it on another computer and only remotely, then the iteration count is not required at all.
@advanced_1230_h3
@advanced_1231_h3
File Encryption
@advanced_1231_p
@advanced_1232_p
The database files can be encrypted using two different algorithms: AES-128 and XTEA (using 32 rounds). The reasons for supporting XTEA is performance (XTEA is about twice as fast as AES) and to have an alternative algorithm if AES is suddenly broken.
@advanced_1232_p
@advanced_1233_p
When a user tries to connect to an encrypted database, the combination of the word 'file', @, and the file password is hashed using SHA-256. This hash value is transmitted to the server.
@advanced_1233_p
@advanced_1234_p
When a new database file is created, a new cryptographically secure random salt value is generated. The size of the salt is 64 bit. The combination of the file password hash and the salt value is hashed 1024 times using SHA-256. The reason for the iteration is to make it harder for an attacker to calculate hash values for common passwords.
@advanced_1234_p
@advanced_1235_p
The resulting hash value is used as the key for the block cipher algorithm (AES-128 or XTEA with 32 rounds). Then, an initialization vector (IV) key is calculated by hashing the key again using SHA-256. This is to make sure the IV is unknown to the attacker. The reason for using a secret IV is to protect against watermark attacks.
@advanced_1235_p
@advanced_1236_p
Before saving a block of data (each block is 8 bytes long), the following operations are executed: First, the IV is calculated by encrypting the block number with the IV key (using the same block cipher algorithm). This IV is combined with the plain text using XOR. The resulting data is encrypted using the AES-128 or XTEA algorithm.
@advanced_1236_p
@advanced_1237_p
When decrypting, the operation is done in reverse. First, the block is decrypted using the key, and then the IV is calculated combined with the decrypted text using XOR.
@advanced_1237_p
@advanced_1238_p
Therefore, the block cipher modes of operation is CBC (Cipher-block chaining), but each chain is only one block long. The advantage over the ECB (Electronic codebook) mode is that patterns in the data are not revealed, and the advantage over multi block CBC is that flipped cipher text bits are not propagated to flipped plaintext bits in the next block.
@advanced_1238_p
@advanced_1239_p
Database encryption is meant for securing the database while it is not in use (stolen laptop and so on). It is not meant for cases where the attacker has access to files while the database is in use. When he has write access, he can for example replace pieces of files with pieces of older versions and manipulate data like this.
@advanced_1239_p
@advanced_1240_p
File encryption slows down the performance of the database engine. Compared to unencrypted mode, database operations take about 2.2 times longer when using XTEA, and 2.5 times longer using AES (embedded mode).
@advanced_1240_h3
@advanced_1241_h3
SSL/TLS Connections
@advanced_1241_p
@advanced_1242_p
Remote SSL/TLS connections are supported using the Java Secure Socket Extension (SSLServerSocket / SSLSocket). By default, anonymous SSL is enabled. The default cipher suite is <code>SSL_DH_anon_WITH_RC4_128_MD5</code> .
@advanced_1242_h3
@advanced_1243_h3
HTTPS Connections
@advanced_1243_p
@advanced_1244_p
The web server supports HTTP and HTTPS connections using SSLServerSocket. There is a default self-certified certificate to support an easy starting point, but custom certificates are supported as well.
@advanced_1244_h2
@advanced_1245_h2
Universally Unique Identifiers (UUID)
@advanced_1245_p
@advanced_1246_p
This database supports the UUIDs. Also supported is a function to create new UUIDs using a cryptographically strong pseudo random number generator. With random UUIDs, the chance of two having the same value can be calculated using the probability theory. See also 'Birthday Paradox'. Standardized randomly generated UUIDs have 122 random bits. 4 bits are used for the version (Randomly generated UUID), and 2 bits for the variant (Leach-Salz). This database supports generating such UUIDs using the built-in function RANDOM_UUID(). Here is a small program to estimate the probability of having two identical UUIDs after generating a number of values:
@advanced_1246_p
@advanced_1247_p
Some values are:
@advanced_1247_p
@advanced_1248_p
To help non-mathematicians understand what those numbers mean, here a comparison: One's annual risk of being hit by a meteorite is estimated to be one chance in 17 billion, that means the probability is about 0.000'000'000'06.
@advanced_1248_h2
@advanced_1249_h2
Settings Read from System Properties
@advanced_1249_p
@advanced_1250_p
Some settings of the database can be set on the command line using -DpropertyName=value. It is usually not required to change those settings manually. The settings are case sensitive. Example:
@advanced_1250_p
@advanced_1251_p
The current value of the settings can be read in the table INFORMATION_SCHEMA.SETTINGS.
@advanced_1251_p
@advanced_1252_p
For a complete list of settings, see <a href="../javadoc/org/h2/constant/SysProperties.html">SysProperties</a> .
@advanced_1252_h2
@advanced_1253_h2
Setting the Server Bind Address
@advanced_1253_p
@advanced_1254_p
Usually server sockets accept connections on any/all local addresses. This may be a problem on multi-homed hosts. To bind only to one address, use the system property h2.bindAddress. This setting is used for both regular server sockets and for SSL server sockets. IPv4 and IPv6 address formats are supported.
@advanced_1254_h2
@advanced_1255_h2
Glossary and Links
@advanced_1255_th
@advanced_1256_th
Term
@advanced_1256_th
@advanced_1257_th
Description
@advanced_1257_td
@advanced_1258_td
AES-128
@advanced_1258_td
@advanced_1259_td
A block encryption algorithm. See also: <a href="http://en.wikipedia.org/wiki/Advanced_Encryption_Standard">Wikipedia: AES</a>
@advanced_1259_td
@advanced_1260_td
Birthday Paradox
@advanced_1260_td
@advanced_1261_td
Describes the higher than expected probability that two persons in a room have the same birthday. Also valid for randomly generated UUIDs. See also: <a href="http://en.wikipedia.org/wiki/Birthday_paradox">Wikipedia: Birthday Paradox</a>
@advanced_1261_td
@advanced_1262_td
Digest
@advanced_1262_td
@advanced_1263_td
Protocol to protect a password (but not to protect data). See also: <a href="http://www.faqs.org/rfcs/rfc2617.html">RFC 2617: HTTP Digest Access Authentication</a>
@advanced_1263_td
@advanced_1264_td
GCJ
@advanced_1264_td
@advanced_1265_td
GNU Compiler for Java. <a href="http://gcc.gnu.org/java/">http://gcc.gnu.org/java/</a> and <a href="http://nativej.mtsystems.ch">http://nativej.mtsystems.ch/ (not free any more)</a>
@advanced_1265_td
@advanced_1266_td
HTTPS
@advanced_1266_td
@advanced_1267_td
A protocol to provide security to HTTP connections. See also: <a href="http://www.ietf.org/rfc/rfc2818.txt">RFC 2818: HTTP Over TLS</a>
@advanced_1267_td
@advanced_1268_td
Modes of Operation
@advanced_1268_a
@advanced_1269_a
Wikipedia: Block cipher modes of operation
@advanced_1269_td
@advanced_1270_td
Salt
@advanced_1270_td
@advanced_1271_td
Random number to increase the security of passwords. See also: <a href="http://en.wikipedia.org/wiki/Key_derivation_function">Wikipedia: Key derivation function</a>
@advanced_1271_td
@advanced_1272_td
SHA-256
@advanced_1272_td
@advanced_1273_td
A cryptographic one-way hash function. See also: <a href="http://en.wikipedia.org/wiki/SHA_family">Wikipedia: SHA hash functions</a>
@advanced_1273_td
@advanced_1274_td
SQL Injection
@advanced_1274_td
@advanced_1275_td
A security vulnerability where an application generates SQL statements with embedded user input. See also: <a href="http://en.wikipedia.org/wiki/SQL_injection">Wikipedia: SQL Injection</a>
@advanced_1275_td
@advanced_1276_td
Watermark Attack
@advanced_1276_td
@advanced_1277_td
Security problem of certain encryption programs where the existence of certain data can be proven without decrypting. For more information, search in the internet for 'watermark attack cryptoloop'
@advanced_1277_td
@advanced_1278_td
SSL/TLS
@advanced_1278_td
@advanced_1279_td
Secure Sockets Layer / Transport Layer Security. See also: <a href="http://java.sun.com/products/jsse/">Java Secure Socket Extension (JSSE)</a>
@advanced_1279_td
@advanced_1280_td
XTEA
@advanced_1280_td
@advanced_1281_td
A block encryption algorithm. See also: <a href="http://en.wikipedia.org/wiki/XTEA">Wikipedia: XTEA</a>
@build_1000_h1
......@@ -2603,7 +2606,7 @@ lumber-mill.co.jp, Japan
Oliver Computing LLC, USA
@history_1034_li
Harpal Grover, USA
Harpal Grover Consulting Inc., USA
@installation_1000_h1
Installation
......
......@@ -471,376 +471,379 @@ PGプロトコルサポートの制限
@advanced_1156_p
現時点では、PostgreSQLネットワークプロトコルのサブセットのみ実装されています。また、カタログ、またはテキストエンコーディングでのSQLレベル上の互換性問題がある可能性があります。問題は発見されたら修正されます。現在、PGプロトコルが使用されている時、ステートメントはキャンセルされません。
@advanced_1157_h3
@advanced_1157_p
#PostgreSQL ODBC Driver Setup requires a database password, that means it is not possible to connect to H2 databases without password. This is a limitation of the ODBC driver.
@advanced_1158_h3
セキュリティ考慮
@advanced_1158_p
@advanced_1159_p
現在、PGサーバーはchallenge response、またはパスワードの暗号化をサポートしていません。パスワードが読みやすいため、アタッカーがODBCドライバとサーバー間でのデータ転送を傾聴できる場合、これは問題になるでしょう。また、暗号化SSL接続も現在使用不可能です。そのため、ODBCドライバはセキュリティが重視される場面においては使用されるべきではありません。
@advanced_1159_h2
@advanced_1160_h2
ACID
@advanced_1160_p
@advanced_1161_p
データベースの世界では、ACIDとは以下を表しています:
@advanced_1161_li
@advanced_1162_li
Atomicity (原子性) : トランザクションはアトミックでなければならず、全てのタスクが実行されたか、実行されないかの どちらかであるという意味です。
@advanced_1162_li
@advanced_1163_li
Consistency (一貫性) : 全てのオペレーションは定義された制約に従わなくてはいけません。
@advanced_1163_li
@advanced_1164_li
Isolation (独立性 / 分離性) : トランザクションはそれぞれ独立 (隔離) されていなくてはなりません。
@advanced_1164_li
@advanced_1165_li
Durability (永続性) : コミットされたトランザクションは失われません。
@advanced_1165_h3
@advanced_1166_h3
Atomicity (原子性)
@advanced_1166_p
@advanced_1167_p
このデータベースでのトランザクションは常にアトミックです。
@advanced_1167_h3
@advanced_1168_h3
Consistency (一貫性)
@advanced_1168_p
@advanced_1169_p
このデータベースは常に一貫性のある状態です。 参照整合性のルールは常に実行されます。
@advanced_1169_h3
@advanced_1170_h3
Isolation (独立性 / 分離性)
@advanced_1170_p
@advanced_1171_p
H2は、他の多くのデータベースシステムと同様に、デフォルトの分離レベルは "read committed" です。これはより良いパフォーマンスを提供しますが、トランザクションは完全に分離されていないということも意味します。H2はトランザクション分離レベル "serializable"、"read committed"、"read uncommitted" をサポートしています。
@advanced_1171_h3
@advanced_1172_h3
Durability (永続性)
@advanced_1172_p
@advanced_1173_p
このデータベースは、全てのコミットされたトランザクションが電源異常に耐えられるということを保証しません。全てのデータベースが電源異常の状況において、一部トランザクションが失われるということをテストは示しています (詳細は下記をご覧下さい)。トランザクションが失われることを容認できない場面では、ノートパソコン、またはUPS (無停電電源装置) を使用します。永続性がハードウェア異常の起こり得る全ての可能性に対して必要とされるのであれば、H2クラスタリングモードのようなクラスタリングが使用されるべきです。
@advanced_1173_h2
@advanced_1174_h2
永続性問題
@advanced_1174_p
@advanced_1175_p
完全な永続性とは、全てのコミットされたトランザクションは電源異常に耐えられる、ということを意味します。 いくつかのデータベースは、永続性を保証すると主張していますが、このような主張は誤っています。 永続性テストはH2、HSQLDB、PostgreSQL、Derbyに対して実行されました。これらの全てのデータベースは、 時々コミットされたトランザクションを失います。このテストはH2ダウンロードに含まれています。 org.h2.test.poweroff.Test をご覧下さい。
@advanced_1175_h3
@advanced_1176_h3
永続性を実現する (しない) 方法
@advanced_1176_p
@advanced_1177_p
失われなかったコミット済みトランザクションは、最初に思うよりもより複雑だということを理解して下さい。 完全な永続性を保障するためには、データベースは、コミットの呼び出しが返ってくる前に ログレコードがハードドライブ上にあることを確実にしなければなりません。 これを行うために、データベースは異なったメソッドを使用します。ひとつは "同期書き込み" ファイルアクセスモードを使用することです。Javaでは、RandomAccessFile はモード "rws" と "rwd" を サポートしています:
@advanced_1177_li
@advanced_1178_li
rwd: それぞれのファイル内容の更新は、元になるストレージデバイスと同時に書き込まれます。
@advanced_1178_li
@advanced_1179_li
rws: rwdに加えて、それぞれのメタデータの更新は同時に書き込まれます。
@advanced_1179_p
@advanced_1180_p
この特徴はDerbyで使用されています。それらのモードのうちのひとつは、テスト (org.h2.test.poweroff.TestWrite) において、毎秒およそ5万件の書き込み操作を実現します。オペレーティングシステムのライトバッファーが無効の時でさえも、 書き込み速度は毎秒およそ5万件です。この特徴はディスクを交換させるというものではありません。 なぜなら、全てのバッファーをフラッシュするのではないからです。テストはファイル内の同じバイトを何度も更新しました。 もしハードドライブがこの速度での書き込みが可能なら、ディスクは少なくても毎秒5万回転か、 または300万 RPM (revolutions per minute 回転毎分) を行う必要があります。 そのようなハードドライブは存在しません。テストで使用されたハードドライブは、およそ7200 RPM、または 毎秒120回転です。これがオーバーヘッドなので、最大書き込み速度はこれより低くなくてはなりません。
@advanced_1180_p
@advanced_1181_p
バッファーは fsync 関数を呼ぶことによってフラッシュされます。Javaでこれを行う二つの方法があります:
@advanced_1181_li
@advanced_1182_li
FileDescriptor.sync() ドキュメンテーションには、これは強制的に全てのシステムバッファーに基本となる デバイスとの同期を取らせる、と書かれています。このFileDescriptorに関連するバッファーのインメモリでの 変更コピーが全て物理メディアに書かれた後、Syncは返ることになっています。
@advanced_1182_li
@advanced_1183_li
FileChannel.force() (JDK 1.4 以来) このメソッドは、強制的にこのチャネルのファイルの更新は それを含むストレージデバイスに書き込まれることを行います。
@advanced_1183_p
@advanced_1184_p
デフォルトでは、MySQLはそれぞれのコミットごとに fsync を呼びます。それらのメソッドのうちひとつを使用している時、 毎秒およそ60件だけが実行され、使用されているハードドライブのRPM速度と一貫性があります。 残念ながら、FileDescriptor.sync() または FileChannel.force() を呼んだ時でさえも データは常にハードドライブに存続するとは限りません。なぜなら、多くのハードドライブは fsync() に従わないからです: http://hardware.slashdot.org/article.pl?sid=05/05/13/0529252 内の"Your Hard Drive Lies to You" をご覧下さい。Mac OS X では、fsync はハードドライブバッファーをフラッシュしません: http://lists.apple.com/archives/darwin-dev/2005/Feb/msg00072.html そのため状況は混乱していて、 問題があることをテストは証明しています。
@advanced_1184_p
@advanced_1185_p
ハードドライブバッファーを懸命にフラッシュしようと試みると、パフォーマンスは非常に悪いものになります。 最初に、ハードドライブは実際には全てのバッファーをフラッシュしているということを確かめることが必要です。 テストは信頼性ある方法でこれが行われていないことを示しています。その結果、トランザクションの最大数は毎秒およそ60件です。 これらの理由により、H2のデフォルト性質はコミットされたトランザクションの書き込みを遅らせることです。
@advanced_1185_p
@advanced_1186_p
H2では、電源異常の後、1秒以上のコミットされたトランザクションが失われます。 この性質を変更するためには。 SET WRITE_DELAY と CHECKPOINT SYNC を使用します。 多くの他のデータベースも同様に遅延コミットをサポートしています。パフォーマンス比較では、 遅延コミットは、サポートする全てのデータベースによって使用されました。
@advanced_1186_h3
@advanced_1187_h3
永続性テストを実行する
@advanced_1187_p
@advanced_1188_p
このデータベースと他のデータベースの、永続性 / 非永続性テストを行うために、 パッケージ内 org.h2.test.poweroff のテストアプリケーションを使用することができます。 ネットワーク接続の二つのコンピューターがこのテストを実行するのに必要です。 ひとつのコンピューターは、他のコンピューター上でテストアプリケーションが実行されている間 (電源は切られています) ただ聞いています。リスナーアプリケーションのコンピューターは TCP/IP ポートを開き、 次の接続のために聞きます。二つ目のコンピューターは最初リスナーに接続し、データベースを作成して レコードの挿入を開始します。この接続は "autocommit" に設定されます。それぞれのレコード挿入後のコミットが 自動的に行われるという意味です。その後、テストコンピューターはこのレコードの挿入に成功したということを リスナーに通知します。リスナーコンピューターは10秒ごとに最後に挿入されたレコードを表示します。 電源を手動でOFFにしてコンピューターを再起動し、アプリケーションを再び実行します。 多くのケースで、リスナーコンピューターが知る全てのレコードを含むデータベースはないということがわかります。 詳細は、リスナーのソースコードとテストアプリケーションを参照して下さい。
@advanced_1188_h2
@advanced_1189_h2
リカバーツールを使用する
@advanced_1189_p
@advanced_1190_p
リカバーツールはデータベースが破損している場合においても、 データファイルのコンテンツを復元するために使用されます。現段階では、ログファイルのコンテンツ、 または大きなオブジェクト (CLOB または BLOB) は復元しません。 このツールを実行するには、このコマンドラインをタイプして下さい:
@advanced_1190_p
@advanced_1191_p
現在のディレクトリのそれぞれのデータベースのために、テキストファイルが作られます。 このファイルには、データベースのスキーマを再び作成するために、行挿入ステートメント (データのための) と data definition (DDL) ステートメントを含んでいます。このファイルは、行挿入ステートメントが 正しいテーブル名を保持していないため、直接実行するこはできません。そのため、 ファイルは実行する前に手動で前処理を行う必要があります。
@advanced_1191_h2
@advanced_1192_h2
ファイルロックプロトコル
@advanced_1192_p
@advanced_1193_p
データベースが開かれるときはいつも、データベースが使用中であると他のプロセスに合図するためにロックファイルが作成されます。もしデータベースが閉じられるか、データベースを開いたプロセスが終了するなら、ロックファイルは削除されます。
@advanced_1193_p
@advanced_1194_p
特別なケースでは (例えば、停電のためプロセスが正常に終了されなかった場合)、 ロックファイルは作られたプロセスによって削除されません。これは、ロックファイルの存在は、 ファイルロックのための安全なプロトコルではない、ということを意味しています。 しかし、このソフトウェアはデータベースファイルを守るため、challenge-responseプロトコルを使用します。 セキュリティ (同じデータベースファイルは、同時に二つのプロセスによって開かれてはいけない) と シンプリシティー (ロックファイルはユーザーによって手動で削除される必要がない) の両方を備えるために 二つのメソッド (アルゴリズム) が実行されます。二つのメソッドは、"Fileメソッド" と "Socketメソッド" です。
@advanced_1194_h3
@advanced_1195_h3
ファイルロックメソッド "File"
@advanced_1195_p
@advanced_1196_p
データベースファイルロックのデフォルトメソッドは "Fileメソッド" です。アルゴリズム:
@advanced_1196_li
@advanced_1197_li
ロックファイルが存在しない時は、作成されます (アトミックオペレーション File.createNewFile を使用する)。 その時、プロセスは少し (20ms) 待機し、再びファイルをチェックします。 もしファイルがこの間に変更されたら、オペレーションは中止されます。 ロックファイルを作成したすぐ後にプロセスがロックファイルを削除する時、 これはレースコンディションから保護し、三番目のプロセスはファイルを再び作成します。 二つのライターしか存在しなければ、これは起こりません。
@advanced_1197_li
@advanced_1198_li
もしファイルが作成されたら、ロックメソッド ("file") でランダムな番号が一緒に挿入されます。 その後、ファイルが他のスレッド/ プロセスによって削除、または 修正された時、定期的にチェックする (デフォルトでは毎秒1回) watchdogスレッドは開始されます。 これが起きる時はいつも、ファイルは古いデータに上書きされます。システムが非常に混み合っている時でさえも、 非検出の状態で処理できないロックファイルを変更するために、watchdogスレッドは最優先に実行します。 しかし、watchdogスレッドはほとんどの時間待機しているため、非常に小さなリソース (CPU time) を使用します。 また、watchdogはハードディスクから読み取りのみ行い、書き込みはしません。
@advanced_1198_li
@advanced_1199_li
もしロックファイルが存在し、20ms内に変更されたら、プロセスは数回 (10回以上) 待機します。 まだ変更されていたら、例外が投げられます (データベースはロックされます)。 多数の並列ライターで競合している状態を排除するためにこれが行われます。 その後、ファイルは新しいバージョンに上書きされます。 そして、スレッドは2秒間待機します。もしファイルを保護するwatchdogスレッドが存在したら、 変更は上書きし、このプロセスはデータベースをロックするために機能しなくなります。 しかし、もしwatchdogスレッドが存在しなければ、ロックファイルはこのスレッドによって 書かれたままの状態です。このケースでは、ファイルは削除され、自動的にまた作成されます。 watchdogスレッドはこのケースでは起動され、ファイルはロックされます。
@advanced_1199_p
@advanced_1200_p
このアルゴリズムは100以上の並列スレッドでテストされました。いくつかのケースでは、 データベースをロックしようとする多数の並列スレッドが存在する時、それらはしばらくお互いをブロックします (それらのうちどれかがファイルをロックすることができないことを意味します)。 しかし、ファイルは同時に二つのスレッドによってロックされることは決してありません。 しかし、多数の並列スレッド / プロセスを使用することは一般的な使用ケースではありません。 通常、データベースを開くことができなかったり、(速い)ループのやり直しができなかったりした場合、 アプリケーションはユーザーにエラーを投げるべきです。
@advanced_1200_h3
@advanced_1201_h3
ファイルロックメソッド "Socket"
@advanced_1201_p
@advanced_1202_p
実行される二つ目のロックメカニズムがありますが、 デフォルトでは使用不可です。アルゴリズムは:
@advanced_1202_li
@advanced_1203_li
ロックファイルが存在しない時は、作成されます。その時、サーバーソケットは定義されたポートで開かれ、 開かれた状態を保ちます。開かれたデータベースのプロセスのポートとIPアドレスはロックファイルの中に書かれています。
@advanced_1203_li
@advanced_1204_li
もしロックファイルが存在し、ロックメソッドが "file" なら、ソフトウェアは "file" メソッドにスイッチします。
@advanced_1204_li
@advanced_1205_li
もしロックファイルが存在し、ロックメソッドが "socket" なら、プロセスはポートが使用されているかチェックします。 最初のプロセスがまだ実行されていたら、ポートは使用されていれ、このプロセスは例外を投げます (database is in use)。 最初のプロセスが失われたら (例えば、停電または、仮想マシンの異常終了のため)、ポートは解除されます。 新しいプロセスはロックファイルを削除し、再び起動します。
@advanced_1205_p
@advanced_1206_p
このメソッドは、活発に毎秒同じファイルをポーリングする (読み込む) watchdogスレッドを必要としていません。 このメソッドの問題は、ファイルがネットワークシェアに保存されたら、二つのプロセスは (異なるコンピューターで実行中の)、 TCP/IP接続を直接保持していなければ、同じデータベースファイルを開くことができます。
@advanced_1206_h2
@advanced_1207_h2
SQLインジェクションに対する防御
@advanced_1207_h3
@advanced_1208_h3
SQLインジェクションとは
@advanced_1208_p
@advanced_1209_p
このデータベースエンジンは "SQLインジェクション" として知られる セキュリティ脆弱性の解決策を備えています。 これは、SQLインジェクションの意味とは何か、 についての短い説明です。いくつかのアプリケーションは、エンベッドユーザーがこのように入力する SQLステートメントを構築します:
@advanced_1209_p
@advanced_1210_p
このメカニズムがアプリケーションのどこかで使用され、ユーザー入力が正しくないフィルター処理、 またはエンベッドなら、ユーザーはパスワード: ' OR ''=' のような (この例の場合) 特別に作られた入力を使用することによって、SQLの機能、またはステートメントに入り込むことが可能です。 このケースでは、ステートメントはこのようになります:
@advanced_1210_p
@advanced_1211_p
データベースに保存されたパスワードが何であっても、これは常に正しいものになります。 SQLインジェクションについての詳細は、用語集とリンク をご覧下さい。
@advanced_1211_h3
@advanced_1212_h3
リテラルを無効にする
@advanced_1212_p
@advanced_1213_p
ユーザー入力が直接SQLステートメントに組み込まれなければ、 SQLインジェクションは不可能です。上記の問題の簡単な解決方法は、PreparedStatementを使用することです:
@advanced_1213_p
@advanced_1214_p
このデータベースは、ユーザー入力をデータベースに通す時、パラメータの使用を強制する方法を提供しています。 SQLステートメントの組み込まれたリテラルを無効にすることでこれを実行します。 次のステートメントを実行します:
@advanced_1214_p
@advanced_1215_p
#Afterwards, SQL statements with text and number literals are not allowed any more. That means, SQL statement of the form WHERE NAME='abc' or WHERE CustomerId=10 will fail. It is still possible to use PreparedStatements and parameters as described above. Also, it is still possible to generate SQL statements dynamically, and use the Statement API, as long as the SQL statements do not include literals. There is also a second mode where number literals are allowed: SET ALLOW_LITERALS NUMBERS. To allow all literals, execute SET ALLOW_LITERALS ALL (this is the default setting). Literals can only be enabled or disabled by an administrator.
@advanced_1215_h3
@advanced_1216_h3
定数を使用する
@advanced_1216_p
@advanced_1217_p
リテラルを無効にするということは、ハードコード化された "定数" リテラルを無効にする、 ということも意味します。このデータベースは、CREATE CONSTANT コマンドを使用して定数を定義することをサポートしています。 定数はリテラルが有効であるときのみ定義することができますが、リテラルが無効の時でも使用することができます。 カラム名の名前の衝突を避けるために、定数は他のスキーマで定義できます:
@advanced_1217_p
@advanced_1218_p
リテラルが有効の時でも、クエリーやビューの中でハードコード化された数値リテラル、 またはテキストリテラルの代わりに、定数を使用する方がより良いでしょう。With 定数では、タイプミスはコンパイル時に発見され、ソースコードは理解、変更しやすくなります。
@advanced_1218_h3
@advanced_1219_h3
ZERO() 関数を使用する
@advanced_1219_p
@advanced_1220_p
組み込み関数 ZERO() がすでにあるため、 数値 0 のための定数を作る必要はありません:
@advanced_1220_h2
@advanced_1221_h2
#Restricting Class Loading and Usage
@advanced_1221_p
@advanced_1222_p
#By default there is no restriction on loading classes and executing Java code for admins. That means an admin may call system functions such as System.setProperty by executing:
@advanced_1222_p
@advanced_1223_p
#To restrict users (including admins) from loading classes and executing code, the list of allowed classes can be set in the system property h2.allowedClasses in the form of a comma separated list of classes or patterns (items ending with '*'). By default all classes are allowed. Example:
@advanced_1223_p
@advanced_1224_p
#This mechanism is used for all user classes, including database event listeners, trigger classes, user defined functions, user defined aggregate functions, and JDBC driver classes (with the exception of the H2 driver) when using the H2 Console.
@advanced_1224_h2
@advanced_1225_h2
セキュリティプロトコル
@advanced_1225_p
@advanced_1226_p
次の文章は、このデータベースで使用されている セキュリティプロトコルのドキュメントです。これらの記述は非常に専門的で、 根本的なセキュリティの基本をすでに知っているセキュリティ専門家のみを対象としています。
@advanced_1226_h3
@advanced_1227_h3
ユーザーパスワードの暗号化
@advanced_1227_p
@advanced_1228_p
ユーザーがデータベースに接続しようとする時、ユーザー名の組み合わせ、@、パスワードは SHA-256 を使用してハッシュ化され、このハッシュ値はデータベースに送信されます。 この手順は、クライアントとサーバー間の転送をアタッカーが聞ける (非暗号化できる) のであれば、 再使用する値からのアタッカーを試みることはありません。しかし、パスワードはクライアントとサーバー間で 暗号化されていない接続を使用している時でさえも、プレーンテキストで送信されることはありません これはもしユーザーが、異なる場面で同じパスワードを再利用しても、このパスワードはある程度まで保護されます。 詳細は"RFC 2617 - HTTP Authentication: Basic and Digest Access Authentication" もご覧下さい。
@advanced_1228_p
@advanced_1229_p
新しいデータベース、またはユーザーが作られた時、暗号化された安全なランダムの 新しいsalt値が生成されます。salt値のサイズは 64 bit です。 ランダムなsaltを使用することによって、多数の異なった (通常、使用された) パスワードのハッシュ値を アタッカーに再計算されるリスクが軽減します。
@advanced_1229_p
@advanced_1230_p
ユーザーパスワードのハッシュ値の組み合わせと (上記をご覧下さい) saltは SHA-256を使用してハッシュ化されます。 結果の値はデータベースに保存されます。ユーザーがデータベースに接続しようとする時、 データベースは、保存されたsalt値のユーザーパスワードのハッシュ値と計算されたハッシュ値を結合します。 他の製品は複数の反復 (ハッシュ値を繰り返しハッシュする) を使用していますが、 この製品ではサービス攻撃の拒絶 (アタッカーが偽のパスワードで接続しようとするところや、 サーバーがそれぞれのパスワードのハッシュ値を計算するのに長い時間費やすところ) のリスクを軽減するのに これは使用しません。理由は: もしアタッカーがハッシュ化されたパスワードにアクセスしたら、 プレーンテキストのデータにもアクセスできるため、パスワードはもはや必要ではなくなってしまいます。 もしデータが、保存されている他のコンピューターによって保護されていて、遠隔のみであるなら、 反復回数は全く必要とされません。
@advanced_1230_h3
@advanced_1231_h3
ファイル暗号化
@advanced_1231_p
@advanced_1232_p
データベースファイルは二つの異なるアルゴリズムを使用して、暗号化されます: AES-128 と XTEA です (32 ラウンドを使用)。 XTEAをサポートする理由はパフォーマンス (XTEAはAESのおよそ二倍の速さです) と、AESが突然壊れた場合、代わりとなるアルゴリズムを 持っているからです。
@advanced_1232_p
@advanced_1233_p
ユーザーが暗号化されたデータベースに接続しようとした時、"file" という単語と、@と、 ファイルパスワードの組み合わせは、SHA-256を使用してハッシュ化されます。 このハッシュ値はサーバーに送信されます。
@advanced_1233_p
@advanced_1234_p
新しいデータベースファイルが作られた時、暗号化された安全なランダムの新しいsalt値が生成されます。 このsaltのサイズは 64 bitです。ファイルパスワードのハッシュとsalt値の組み合わせは、 SHA-256を使用して1024回ハッシュ化されます。反復の理由は、アタッカーが通常のパスワードの ハッシュ値を計算するよりも困難にするためです。
@advanced_1234_p
@advanced_1235_p
ハッシュ値の結果は、ブロック暗号アルゴリズム (AES-128、または 32ラウンドのXTEA) のためのキーとして 使用されます。その時、初期化ベクター (IV) キーは、再びSHA-256を使用してキーをハッシュ化することによって 計算されます。IVはアタッカーに知らないということを確認して下さい。秘密のIVを使用する理由は、 ウォーターマークアタック (電子透かし攻撃) を防御するためです。
@advanced_1235_p
@advanced_1236_p
データのブロックを保存する前に (それぞれのブロックは 8 バイト長)、次のオペレーションを 実行します: 最初に、IVはIVキー (同じblock cipher algorithmを使用して) でブロックナンバーを 暗号化することによって計算されます。このIVはXORを使用してプレーンテキストと併用されます。 結果データはAES-128、またはXTEAアルゴリズムを使用して暗号化されます。
@advanced_1236_p
@advanced_1237_p
復号化の時、オペレーションは反対に行われます。最初に、ブロックはキーを使用して復号化され、 その時、IVはXORを使用して復号化テキストと併用されます。
@advanced_1237_p
@advanced_1238_p
その結果、オペレーションのブロック暗号モードはCBT (Cipher-block chaining) ですが、 それぞれの連鎖はたったひとつのブロック長です。ECB (Electronic codebook) モードに優る利点は、 データのパターンが明らかにされない点で、複数のブロックCBCに優る利点は、 はじき出された暗号テキストビットは次のブロックではじき出されたプレーンテキストビットに伝播されないという点です。
@advanced_1238_p
@advanced_1239_p
データベース暗号化は、使用されていない間は (盗まれたノートパソコン等) 安全なデータベースだということを 意味します。これは、データベースが使用されている間に、アタッカーがファイルにアクセスしたというケースを 意味するのではありません。アタッカーが書き込みアクセスをした時、例えば、 彼はファイルの一部を古いバージョンに置き換え、データをこのように操ります。
@advanced_1239_p
@advanced_1240_p
ファイル暗号化はデータベースエンジンのパフォーマンスを低速にします。非暗号化モードと比較すると、 データベースオペレーションは、XTEAを使用する時はおよそ2.2倍長くかかり、 AESを使用する時は2.5倍長くかかります (エンベッドモード)。
@advanced_1240_h3
@advanced_1241_h3
SSL/TLS 接続
@advanced_1241_p
@advanced_1242_p
遠隔SSL/TLS接続は、Java Secure Socket Extension (SSLServerSocket / SSLSocket) の使用をサポートしています。デフォルトでは、匿名のSSLは使用可能です。デフォルトの暗号化パッケージソフトは SSL_DH_anon_WITH_RC4_128_MD5 です。
@advanced_1242_h3
@advanced_1243_h3
HTTPS 接続
@advanced_1243_p
@advanced_1244_p
webサーバーは、SSLServerSocketを使用したHTTP と HTTPS接続をサポートします。 簡単に開始できるように、デフォルトの自己認証された証明書がありますが、 カスタム証明書も同様にサポートされています。
@advanced_1244_h2
@advanced_1245_h2
汎用一意識別子 (UUID)
@advanced_1245_p
@advanced_1246_p
このデータベースはUUIDをサポートしています。 また、暗号化強力疑似乱数ジェネレーターを使用して新しいUUIDを作成する関数をサポートしています。 同じ値をもつ二つの無作為なUUIDが存在する可能性は、確率論を使用して計算されることができます。 "Birthday Paradox" もご覧下さい。標準化された無作為に生成されたUUIDは、122の無作為なビットを保持しています。 4ビットはバージョン(無作為に生成されたUUID) に、2ビットはバリアント (Leach-Salz) に使用されます。 このデータベースは組み込み関数 RANDOM_UUID() を使用してこのようなUUIDを生成することをサポートしています。 ここに、値の数字が生成された後、二つの 同一のUUIDが生じる可能性を見積もる小さなプログラムがあります:
@advanced_1246_p
@advanced_1247_p
いくつかの値は:
@advanced_1247_p
@advanced_1248_p
人の隕石に衝突するという年に一度の危険性は、170億に一回と見積もられ、それは、確率がおよそ 0.000'000'000'06 だということを意味しています。
@advanced_1248_h2
@advanced_1249_h2
システムプロパティから読み込まれた設定
@advanced_1249_p
@advanced_1250_p
いくつかのデータベースの設定は、-DpropertyName=value を使用してコマンドラインで設定することができます。 通常、これらの設定は手動で変更することは必要とされていません。設定は大文字と小文字を区別しています。 例:
@advanced_1250_p
@advanced_1251_p
#The current value of the settings can be read in the table INFORMATION_SCHEMA.SETTINGS.
@advanced_1251_p
@advanced_1252_p
#For a complete list of settings, see <a href="../javadoc/org/h2/constant/SysProperties.html">SysProperties</a> .
@advanced_1252_h2
@advanced_1253_h2
#Setting the Server Bind Address
@advanced_1253_p
@advanced_1254_p
#Usually server sockets accept connections on any/all local addresses. This may be a problem on multi-homed hosts. To bind only to one address, use the system property h2.bindAddress. This setting is used for both regular server sockets and for SSL server sockets. IPv4 and IPv6 address formats are supported.
@advanced_1254_h2
@advanced_1255_h2
用語集とリンク
@advanced_1255_th
@advanced_1256_th
用語
@advanced_1256_th
@advanced_1257_th
説明
@advanced_1257_td
@advanced_1258_td
AES-128
@advanced_1258_td
@advanced_1259_td
ブロック暗号化アルゴリズム。こちらもご覧下さい:<a href="http://en.wikipedia.org/wiki/Advanced_Encryption_Standard">Wikipedia: AES</a>
@advanced_1259_td
@advanced_1260_td
Birthday Paradox
@advanced_1260_td
@advanced_1261_td
部屋にいる二人が同じ誕生日の可能性が期待された以上に高いということを説明する。 また、有効なランダムに生成されたUUID。こちらもご覧下さい:<a href="http://en.wikipedia.org/wiki/Birthday_paradox">Wikipedia: Birthday Paradox</a>
@advanced_1261_td
@advanced_1262_td
Digest
@advanced_1262_td
@advanced_1263_td
パスワードを保護するプロトコル (データは保護しません)。こちらもご覧下さい:<a href="http://www.faqs.org/rfcs/rfc2617.html">RFC 2617: HTTP Digest Access Authentication</a>
@advanced_1263_td
@advanced_1264_td
GCJ
@advanced_1264_td
@advanced_1265_td
JavaのGNUコンパイラー<a href="http://gcc.gnu.org/java/">http://gcc.gnu.org/java/</a> and <a href="http://nativej.mtsystems.ch">http://nativej.mtsystems.ch/ (not free any more)</a>
@advanced_1265_td
@advanced_1266_td
HTTPS
@advanced_1266_td
@advanced_1267_td
セキュリティをHTTP接続に提供するプロトコル。こちらもご覧下さい: <a href="http://www.ietf.org/rfc/rfc2818.txt">RFC 2818: HTTP Over TLS</a>
@advanced_1267_td
@advanced_1268_td
Modes of Operation
@advanced_1268_a
@advanced_1269_a
Wikipedia: Block cipher modes of operation
@advanced_1269_td
@advanced_1270_td
Salt
@advanced_1270_td
@advanced_1271_td
パスワードのセキュリティを増大する乱数。こちらもご覧下さい: <a href="http://en.wikipedia.org/wiki/Key_derivation_function">Wikipedia: Key derivation function</a>
@advanced_1271_td
@advanced_1272_td
SHA-256
@advanced_1272_td
@advanced_1273_td
暗号化の一方方向のハッシュ関数。こちらもご覧下さい:<a href="http://en.wikipedia.org/wiki/SHA_family">Wikipedia: SHA hash functions</a>
@advanced_1273_td
@advanced_1274_td
SQLインジェクション
@advanced_1274_td
@advanced_1275_td
組み込みのユーザー入力でアプリケーションがSQLステートメントを生成するセキュリティ脆弱性 こちらもご覧下さい:<a href="http://en.wikipedia.org/wiki/SQL_injection">Wikipedia: SQL Injection</a>
@advanced_1275_td
@advanced_1276_td
Watermark Attack (透かし攻撃)
@advanced_1276_td
@advanced_1277_td
復号化することなくあるデータの存在を証明できる、ある暗号化プログラムのセキュリティ問題。 詳細は、インターネットで "watermark attack cryptoloop" を検索して下さい。
@advanced_1277_td
@advanced_1278_td
SSL/TLS
@advanced_1278_td
@advanced_1279_td
Secure Sockets Layer / Transport Layer Security。こちらもご覧下さい: <a href="http://java.sun.com/products/jsse/">Java Secure Socket Extension (JSSE)</a>
@advanced_1279_td
@advanced_1280_td
XTEA
@advanced_1280_td
@advanced_1281_td
ブロック暗号化アルゴリズム。こちらもご覧下さい: <a href="http://en.wikipedia.org/wiki/XTEA">Wikipedia: XTEA</a>
@build_1000_h1
......@@ -2605,7 +2608,7 @@ Javaは将来への証明でもあります: 多くの会社がJavaをサポー
#Oliver Computing LLC, USA
@history_1034_li
#Harpal Grover, USA
#Harpal Grover Consulting Inc., USA
@installation_1000_h1
インストール
......@@ -5028,3 +5031,204 @@ Javaアプリケーション内からインデックスを呼び出すことも
@tutorial_1149_p
#Variables that are not set evaluate to NULL. The data type of a user defined variable is the data type of the value assigned to it, that means it is not necessary (or possible) to declare variable names before using them. There are no restrictions on the assigned values, large objects (LOBs) are supported as well.
@~advanced_1157_h3
セキュリティ考慮
@~advanced_1158_p
現在、PGサーバーはchallenge response、またはパスワードの暗号化をサポートしていません。パスワードが読みやすいため、アタッカーがODBCドライバとサーバー間でのデータ転送を傾聴できる場合、これは問題になるでしょう。また、暗号化SSL接続も現在使用不可能です。そのため、ODBCドライバはセキュリティが重視される場面においては使用されるべきではありません。
@~advanced_1159_h2
ACID
@~advanced_1160_p
データベースの世界では、ACIDとは以下を表しています:
@~advanced_1161_li
Atomicity (原子性) : トランザクションはアトミックでなければならず、全てのタスクが実行されたか、実行されないかの どちらかであるという意味です。
@~advanced_1165_h3
Atomicity (原子性)
@~advanced_1166_p
このデータベースでのトランザクションは常にアトミックです。
@~advanced_1167_h3
Consistency (一貫性)
@~advanced_1168_p
このデータベースは常に一貫性のある状態です。 参照整合性のルールは常に実行されます。
@~advanced_1169_h3
Isolation (独立性 / 分離性)
@~advanced_1170_p
H2は、他の多くのデータベースシステムと同様に、デフォルトの分離レベルは "read committed" です。これはより良いパフォーマンスを提供しますが、トランザクションは完全に分離されていないということも意味します。H2はトランザクション分離レベル "serializable"、"read committed"、"read uncommitted" をサポートしています。
@~advanced_1171_h3
Durability (永続性)
@~advanced_1172_p
このデータベースは、全てのコミットされたトランザクションが電源異常に耐えられるということを保証しません。全てのデータベースが電源異常の状況において、一部トランザクションが失われるということをテストは示しています (詳細は下記をご覧下さい)。トランザクションが失われることを容認できない場面では、ノートパソコン、またはUPS (無停電電源装置) を使用します。永続性がハードウェア異常の起こり得る全ての可能性に対して必要とされるのであれば、H2クラスタリングモードのようなクラスタリングが使用されるべきです。
@~advanced_1173_h2
永続性問題
@~advanced_1174_p
完全な永続性とは、全てのコミットされたトランザクションは電源異常に耐えられる、ということを意味します。 いくつかのデータベースは、永続性を保証すると主張していますが、このような主張は誤っています。 永続性テストはH2、HSQLDB、PostgreSQL、Derbyに対して実行されました。これらの全てのデータベースは、 時々コミットされたトランザクションを失います。このテストはH2ダウンロードに含まれています。 org.h2.test.poweroff.Test をご覧下さい。
@~advanced_1175_h3
永続性を実現する (しない) 方法
@~advanced_1176_p
失われなかったコミット済みトランザクションは、最初に思うよりもより複雑だということを理解して下さい。 完全な永続性を保障するためには、データベースは、コミットの呼び出しが返ってくる前に ログレコードがハードドライブ上にあることを確実にしなければなりません。 これを行うために、データベースは異なったメソッドを使用します。ひとつは "同期書き込み" ファイルアクセスモードを使用することです。Javaでは、RandomAccessFile はモード "rws" と "rwd" を サポートしています:
@~advanced_1177_li
rwd: それぞれのファイル内容の更新は、元になるストレージデバイスと同時に書き込まれます。
@~advanced_1179_p
この特徴はDerbyで使用されています。それらのモードのうちのひとつは、テスト (org.h2.test.poweroff.TestWrite) において、毎秒およそ5万件の書き込み操作を実現します。オペレーティングシステムのライトバッファーが無効の時でさえも、 書き込み速度は毎秒およそ5万件です。この特徴はディスクを交換させるというものではありません。 なぜなら、全てのバッファーをフラッシュするのではないからです。テストはファイル内の同じバイトを何度も更新しました。 もしハードドライブがこの速度での書き込みが可能なら、ディスクは少なくても毎秒5万回転か、 または300万 RPM (revolutions per minute 回転毎分) を行う必要があります。 そのようなハードドライブは存在しません。テストで使用されたハードドライブは、およそ7200 RPM、または 毎秒120回転です。これがオーバーヘッドなので、最大書き込み速度はこれより低くなくてはなりません。
@~advanced_1181_li
FileDescriptor.sync() ドキュメンテーションには、これは強制的に全てのシステムバッファーに基本となる デバイスとの同期を取らせる、と書かれています。このFileDescriptorに関連するバッファーのインメモリでの 変更コピーが全て物理メディアに書かれた後、Syncは返ることになっています。
@~advanced_1183_p
デフォルトでは、MySQLはそれぞれのコミットごとに fsync を呼びます。それらのメソッドのうちひとつを使用している時、 毎秒およそ60件だけが実行され、使用されているハードドライブのRPM速度と一貫性があります。 残念ながら、FileDescriptor.sync() または FileChannel.force() を呼んだ時でさえも データは常にハードドライブに存続するとは限りません。なぜなら、多くのハードドライブは fsync() に従わないからです: http://hardware.slashdot.org/article.pl?sid=05/05/13/0529252 内の"Your Hard Drive Lies to You" をご覧下さい。Mac OS X では、fsync はハードドライブバッファーをフラッシュしません: http://lists.apple.com/archives/darwin-dev/2005/Feb/msg00072.html そのため状況は混乱していて、 問題があることをテストは証明しています。
@~advanced_1186_h3
永続性テストを実行する
@~advanced_1187_p
このデータベースと他のデータベースの、永続性 / 非永続性テストを行うために、 パッケージ内 org.h2.test.poweroff のテストアプリケーションを使用することができます。 ネットワーク接続の二つのコンピューターがこのテストを実行するのに必要です。 ひとつのコンピューターは、他のコンピューター上でテストアプリケーションが実行されている間 (電源は切られています) ただ聞いています。リスナーアプリケーションのコンピューターは TCP/IP ポートを開き、 次の接続のために聞きます。二つ目のコンピューターは最初リスナーに接続し、データベースを作成して レコードの挿入を開始します。この接続は "autocommit" に設定されます。それぞれのレコード挿入後のコミットが 自動的に行われるという意味です。その後、テストコンピューターはこのレコードの挿入に成功したということを リスナーに通知します。リスナーコンピューターは10秒ごとに最後に挿入されたレコードを表示します。 電源を手動でOFFにしてコンピューターを再起動し、アプリケーションを再び実行します。 多くのケースで、リスナーコンピューターが知る全てのレコードを含むデータベースはないということがわかります。 詳細は、リスナーのソースコードとテストアプリケーションを参照して下さい。
@~advanced_1188_h2
リカバーツールを使用する
@~advanced_1189_p
リカバーツールはデータベースが破損している場合においても、 データファイルのコンテンツを復元するために使用されます。現段階では、ログファイルのコンテンツ、 または大きなオブジェクト (CLOB または BLOB) は復元しません。 このツールを実行するには、このコマンドラインをタイプして下さい:
@~advanced_1191_h2
ファイルロックプロトコル
@~advanced_1192_p
データベースが開かれるときはいつも、データベースが使用中であると他のプロセスに合図するためにロックファイルが作成されます。もしデータベースが閉じられるか、データベースを開いたプロセスが終了するなら、ロックファイルは削除されます。
@~advanced_1194_h3
ファイルロックメソッド "File"
@~advanced_1195_p
データベースファイルロックのデフォルトメソッドは "Fileメソッド" です。アルゴリズム:
@~advanced_1196_li
ロックファイルが存在しない時は、作成されます (アトミックオペレーション File.createNewFile を使用する)。 その時、プロセスは少し (20ms) 待機し、再びファイルをチェックします。 もしファイルがこの間に変更されたら、オペレーションは中止されます。 ロックファイルを作成したすぐ後にプロセスがロックファイルを削除する時、 これはレースコンディションから保護し、三番目のプロセスはファイルを再び作成します。 二つのライターしか存在しなければ、これは起こりません。
@~advanced_1199_p
このアルゴリズムは100以上の並列スレッドでテストされました。いくつかのケースでは、 データベースをロックしようとする多数の並列スレッドが存在する時、それらはしばらくお互いをブロックします (それらのうちどれかがファイルをロックすることができないことを意味します)。 しかし、ファイルは同時に二つのスレッドによってロックされることは決してありません。 しかし、多数の並列スレッド / プロセスを使用することは一般的な使用ケースではありません。 通常、データベースを開くことができなかったり、(速い)ループのやり直しができなかったりした場合、 アプリケーションはユーザーにエラーを投げるべきです。
@~advanced_1200_h3
ファイルロックメソッド "Socket"
@~advanced_1201_p
実行される二つ目のロックメカニズムがありますが、 デフォルトでは使用不可です。アルゴリズムは:
@~advanced_1202_li
ロックファイルが存在しない時は、作成されます。その時、サーバーソケットは定義されたポートで開かれ、 開かれた状態を保ちます。開かれたデータベースのプロセスのポートとIPアドレスはロックファイルの中に書かれています。
@~advanced_1205_p
このメソッドは、活発に毎秒同じファイルをポーリングする (読み込む) watchdogスレッドを必要としていません。 このメソッドの問題は、ファイルがネットワークシェアに保存されたら、二つのプロセスは (異なるコンピューターで実行中の)、 TCP/IP接続を直接保持していなければ、同じデータベースファイルを開くことができます。
@~advanced_1206_h2
SQLインジェクションに対する防御
@~advanced_1207_h3
SQLインジェクションとは
@~advanced_1208_p
このデータベースエンジンは "SQLインジェクション" として知られる セキュリティ脆弱性の解決策を備えています。 これは、SQLインジェクションの意味とは何か、 についての短い説明です。いくつかのアプリケーションは、エンベッドユーザーがこのように入力する SQLステートメントを構築します:
@~advanced_1211_h3
リテラルを無効にする
@~advanced_1212_p
ユーザー入力が直接SQLステートメントに組み込まれなければ、 SQLインジェクションは不可能です。上記の問題の簡単な解決方法は、PreparedStatementを使用することです:
@~advanced_1215_h3
定数を使用する
@~advanced_1216_p
リテラルを無効にするということは、ハードコード化された "定数" リテラルを無効にする、 ということも意味します。このデータベースは、CREATE CONSTANT コマンドを使用して定数を定義することをサポートしています。 定数はリテラルが有効であるときのみ定義することができますが、リテラルが無効の時でも使用することができます。 カラム名の名前の衝突を避けるために、定数は他のスキーマで定義できます:
@~advanced_1218_h3
ZERO() 関数を使用する
@~advanced_1219_p
組み込み関数 ZERO() がすでにあるため、 数値 0 のための定数を作る必要はありません:
@~advanced_1220_h2
#Restricting Class Loading and Usage
@~advanced_1221_p
#By default there is no restriction on loading classes and executing Java code for admins. That means an admin may call system functions such as System.setProperty by executing:
@~advanced_1224_h2
セキュリティプロトコル
@~advanced_1225_p
次の文章は、このデータベースで使用されている セキュリティプロトコルのドキュメントです。これらの記述は非常に専門的で、 根本的なセキュリティの基本をすでに知っているセキュリティ専門家のみを対象としています。
@~advanced_1226_h3
ユーザーパスワードの暗号化
@~advanced_1227_p
ユーザーがデータベースに接続しようとする時、ユーザー名の組み合わせ、@、パスワードは SHA-256 を使用してハッシュ化され、このハッシュ値はデータベースに送信されます。 この手順は、クライアントとサーバー間の転送をアタッカーが聞ける (非暗号化できる) のであれば、 再使用する値からのアタッカーを試みることはありません。しかし、パスワードはクライアントとサーバー間で 暗号化されていない接続を使用している時でさえも、プレーンテキストで送信されることはありません これはもしユーザーが、異なる場面で同じパスワードを再利用しても、このパスワードはある程度まで保護されます。 詳細は"RFC 2617 - HTTP Authentication: Basic and Digest Access Authentication" もご覧下さい。
@~advanced_1230_h3
ファイル暗号化
@~advanced_1231_p
データベースファイルは二つの異なるアルゴリズムを使用して、暗号化されます: AES-128 と XTEA です (32 ラウンドを使用)。 XTEAをサポートする理由はパフォーマンス (XTEAはAESのおよそ二倍の速さです) と、AESが突然壊れた場合、代わりとなるアルゴリズムを 持っているからです。
@~advanced_1240_h3
SSL/TLS 接続
@~advanced_1241_p
遠隔SSL/TLS接続は、Java Secure Socket Extension (SSLServerSocket / SSLSocket) の使用をサポートしています。デフォルトでは、匿名のSSLは使用可能です。デフォルトの暗号化パッケージソフトは SSL_DH_anon_WITH_RC4_128_MD5 です。
@~advanced_1242_h3
HTTPS 接続
@~advanced_1243_p
webサーバーは、SSLServerSocketを使用したHTTP と HTTPS接続をサポートします。 簡単に開始できるように、デフォルトの自己認証された証明書がありますが、 カスタム証明書も同様にサポートされています。
@~advanced_1244_h2
汎用一意識別子 (UUID)
@~advanced_1245_p
このデータベースはUUIDをサポートしています。 また、暗号化強力疑似乱数ジェネレーターを使用して新しいUUIDを作成する関数をサポートしています。 同じ値をもつ二つの無作為なUUIDが存在する可能性は、確率論を使用して計算されることができます。 "Birthday Paradox" もご覧下さい。標準化された無作為に生成されたUUIDは、122の無作為なビットを保持しています。 4ビットはバージョン(無作為に生成されたUUID) に、2ビットはバリアント (Leach-Salz) に使用されます。 このデータベースは組み込み関数 RANDOM_UUID() を使用してこのようなUUIDを生成することをサポートしています。 ここに、値の数字が生成された後、二つの 同一のUUIDが生じる可能性を見積もる小さなプログラムがあります:
@~advanced_1248_h2
システムプロパティから読み込まれた設定
@~advanced_1249_p
いくつかのデータベースの設定は、-DpropertyName=value を使用してコマンドラインで設定することができます。 通常、これらの設定は手動で変更することは必要とされていません。設定は大文字と小文字を区別しています。 例:
@~advanced_1252_h2
#Setting the Server Bind Address
@~advanced_1253_p
#Usually server sockets accept connections on any/all local addresses. This may be a problem on multi-homed hosts. To bind only to one address, use the system property h2.bindAddress. This setting is used for both regular server sockets and for SSL server sockets. IPv4 and IPv6 address formats are supported.
@~advanced_1254_h2
用語集とリンク
@~advanced_1255_th
用語
@~advanced_1257_td
AES-128
@~advanced_1268_a
Wikipedia: Block cipher modes of operation
@~advanced_1269_td
Salt
......@@ -155,130 +155,131 @@ advanced_1153_td=The database password.
advanced_1154_p=Afterwards, you may use this data source.
advanced_1155_h3=PG Protocol Support Limitations
advanced_1156_p=At this time, only a subset of the PostgreSQL network protocol is implemented. Also, there may be compatibility problems on the SQL level, with the catalog, or with text encoding. Problems are fixed as they are found. Currently, statements can not be cancelled when using the PG protocol.
advanced_1157_h3=Security Considerations
advanced_1158_p=Currently, the PG Server does not support challenge response or encrypt passwords. This may be a problem if an attacker can listen to the data transferred between the ODBC driver and the server, because the password is readable to the attacker. Also, it is currently not possible to use encrypted SSL connections. Therefore the ODBC driver should not be used where security is important.
advanced_1159_h2=ACID
advanced_1160_p=In the database world, ACID stands for\:
advanced_1161_li=Atomicity\: Transactions must be atomic, meaning either all tasks are performed or none.
advanced_1162_li=Consistency\: All operations must comply with the defined constraints.
advanced_1163_li=Isolation\: Transactions must be isolated from each other.
advanced_1164_li=Durability\: Committed transaction will not be lost.
advanced_1165_h3=Atomicity
advanced_1166_p=Transactions in this database are always atomic.
advanced_1167_h3=Consistency
advanced_1168_p=This database is always in a consistent state. Referential integrity rules are always enforced.
advanced_1169_h3=Isolation
advanced_1170_p=For H2, as with most other database systems, the default isolation level is 'read committed'. This provides better performance, but also means that transactions are not completely isolated. H2 supports the transaction isolation levels 'serializable', 'read committed', and 'read uncommitted'.
advanced_1171_h3=Durability
advanced_1172_p=This database does not guarantee that all committed transactions survive a power failure. Tests show that all databases sometimes lose transactions on power failure (for details, see below). Where losing transactions is not acceptable, a laptop or UPS (uninterruptible power supply) should be used. If durability is required for all possible cases of hardware failure, clustering should be used, such as the H2 clustering mode.
advanced_1173_h2=Durability Problems
advanced_1174_p=Complete durability means all committed transaction survive a power failure. Some databases claim they can guarantee durability, but such claims are wrong. A durability test was run against H2, HSQLDB, PostgreSQL, and Derby. All of those databases sometimes lose committed transactions. The test is included in the H2 download, see org.h2.test.poweroff.Test.
advanced_1175_h3=Ways to (Not) Achieve Durability
advanced_1176_p=Making sure that committed transaction are not lost is more complicated than it seems first. To guarantee complete durability, a database must ensure that the log record is on the hard drive before the commit call returns. To do that, databases use different methods. One is to use the 'synchronous write' file access mode. In Java, RandomAccessFile supports the modes "rws" and "rwd"\:
advanced_1177_li=rwd\: Every update to the file's content is written synchronously to the underlying storage device.
advanced_1178_li=rws\: In addition to rwd, every update to the metadata is written synchronously.
advanced_1179_p=This feature is used by Derby. A test (org.h2.test.poweroff.TestWrite) with one of those modes achieves around 50 thousand write operations per second. Even when the operating system write buffer is disabled, the write rate is around 50 thousand operations per second. This feature does not force changes to disk because it does not flush all buffers. The test updates the same byte in the file again and again. If the hard drive was able to write at this rate, then the disk would need to make at least 50 thousand revolutions per second, or 3 million RPM (revolutions per minute). There are no such hard drives. The hard drive used for the test is about 7200 RPM, or about 120 revolutions per second. There is an overhead, so the maximum write rate must be lower than that.
advanced_1180_p=Buffers can be flushed by calling the function fsync. There are two ways to do that in Java\:
advanced_1181_li=FileDescriptor.sync(). The documentation says that this forces all system buffers to synchronize with the underlying device. Sync is supposed to return after all in-memory modified copies of buffers associated with this FileDescriptor have been written to the physical medium.
advanced_1182_li=FileChannel.force() (since JDK 1.4). This method is supposed to force any updates to this channel's file to be written to the storage device that contains it.
advanced_1183_p=By default, MySQL calls fsync for each commit. When using one of those methods, only around 60 write operations per second can be achieved, which is consistent with the RPM rate of the hard drive used. Unfortunately, even when calling FileDescriptor.sync() or FileChannel.force(), data is not always persisted to the hard drive, because most hard drives do not obey fsync()\: see 'Your Hard Drive Lies to You' at http\://hardware.slashdot.org/article.pl?sid\=05/05/13/0529252. In Mac OS X fsync does not flush hard drive buffers\: http\://lists.apple.com/archives/darwin-dev/2005/Feb/msg00072.html. So the situation is confusing, and tests prove there is a problem.
advanced_1184_p=Trying to flush hard drive buffers hard, and if you do the performance is very bad. First you need to make sure that the hard drive actually flushes all buffers. Tests show that this can not be done in a reliable way. Then the maximum number of transactions is around 60 per second. Because of those reasons, the default behavior of H2 is to delay writing committed transactions.
advanced_1185_p=In H2, after a power failure, a bit more than one second of committed transactions may be lost. To change the behavior, use SET WRITE_DELAY and CHECKPOINT SYNC. Most other databases support commit delay as well. In the performance comparison, commit delay was used for all databases that support it.
advanced_1186_h3=Running the Durability Test
advanced_1187_p=To test the durability / non-durability of this and other databases, you can use the test application in the package org.h2.test.poweroff. Two computers with network connection are required to run this test. One computer just listens, while the test application is run (and power is cut) on the other computer. The computer with the listener application opens a TCP/IP port and listens for an incoming connection. The second computer first connects to the listener, and then created the databases and starts inserting records. The connection is set to 'autocommit', which means after each inserted record a commit is performed automatically. Afterwards, the test computer notifies the listener that this record was inserted successfully. The listener computer displays the last inserted record number every 10 seconds. Now, switch off the power manually, then restart the computer, and run the application again. You will find out that in most cases, none of the databases contains all the records that the listener computer knows about. For details, please consult the source code of the listener and test application.
advanced_1188_h2=Using the Recover Tool
advanced_1189_p=The recover tool can be used to extract the contents of a data file, even if the database is corrupted. At this time, it does not extract the content of the log file or large objects (CLOB or BLOB). To run the tool, type on the command line\:
advanced_1190_p=For each database in the current directory, a text file will be created. This file contains raw insert statement (for the data) and data definition (DDL) statement to recreate the schema of the database. This file cannot be executed directly, as the raw insert statements don't have the correct table names, so the file needs to be pre-processed manually before executing.
advanced_1191_h2=File Locking Protocols
advanced_1192_p=Whenever a database is opened, a lock file is created to signal other processes that the database is in use. If database is closed, or if the process that opened the database terminates, this lock file is deleted.
advanced_1193_p=In special cases (if the process did not terminate normally, for example because there was a blackout), the lock file is not deleted by the process that created it. That means the existence of the lock file is not a safe protocol for file locking. However, this software uses a challenge-response protocol to protect the database files. There are two methods (algorithms) implemented to provide both security (that is, the same database files cannot be opened by two processes at the same time) and simplicity (that is, the lock file does not need to be deleted manually by the user). The two methods are 'file method' and 'socket methods'.
advanced_1194_h3=File Locking Method 'File'
advanced_1195_p=The default method for database file locking is the 'File Method'. The algorithm is\:
advanced_1196_li=When the lock file does not exist, it is created (using the atomic operation File.createNewFile). Then, the process waits a little bit (20ms) and checks the file again. If the file was changed during this time, the operation is aborted. This protects against a race condition when a process deletes the lock file just after one create it, and a third process creates the file again. It does not occur if there are only two writers.
advanced_1197_li=If the file can be created, a random number is inserted together with the locking method ('file'). Afterwards, a watchdog thread is started that checks regularly (every second once by default) if the file was deleted or modified by another (challenger) thread / process. Whenever that occurs, the file is overwritten with the old data. The watchdog thread runs with high priority so that a change to the lock file does not get through undetected even if the system is very busy. However, the watchdog thread does use very little resources (CPU time), because it waits most of the time. Also, the watchdog only reads from the hard disk and does not write to it.
advanced_1198_li=If the lock file exists, and it was modified in the 20 ms, the process waits for some time (up to 10 times). If it was still changed, an exception is thrown (database is locked). This is done to eliminate race conditions with many concurrent writers. Afterwards, the file is overwritten with a new version (challenge). After that, the thread waits for 2 seconds. If there is a watchdog thread protecting the file, he will overwrite the change and this process will fail to lock the database. However, if there is no watchdog thread, the lock file will still be as written by this thread. In this case, the file is deleted and atomically created again. The watchdog thread is started in this case and the file is locked.
advanced_1199_p=This algorithm is tested with over 100 concurrent threads. In some cases, when there are many concurrent threads trying to lock the database, they block each other (meaning the file cannot be locked by any of them) for some time. However, the file never gets locked by two threads at the same time. However using that many concurrent threads / processes is not the common use case. Generally, an application should throw an error to the user if it cannot open a database, and not try again in a (fast) loop.
advanced_1200_h3=File Locking Method 'Socket'
advanced_1201_p=There is a second locking mechanism implemented, but disabled by default. The algorithm is\:
advanced_1202_li=If the lock file does not exist, it is created. Then a server socket is opened on a defined port, and kept open. The port and IP address of the process that opened the database is written into the lock file.
advanced_1203_li=If the lock file exists, and the lock method is 'file', then the software switches to the 'file' method.
advanced_1204_li=If the lock file exists, and the lock method is 'socket', then the process checks if the port is in use. If the original process is still running, the port is in use and this process throws an exception (database is in use). If the original process died (for example due to a blackout, or abnormal termination of the virtual machine), then the port was released. The new process deletes the lock file and starts again.
advanced_1205_p=This method does not require a watchdog thread actively polling (reading) the same file every second. The problem with this method is, if the file is stored on a network share, two processes (running on different computers) could still open the same database files, if they do not have a direct TCP/IP connection.
advanced_1206_h2=Protection against SQL Injection
advanced_1207_h3=What is SQL Injection
advanced_1208_p=This database engine provides a solution for the security vulnerability known as 'SQL Injection'. Here is a short description of what SQL injection means. Some applications build SQL statements with embedded user input such as\:
advanced_1209_p=If this mechanism is used anywhere in the application, and user input is not correctly filtered or encoded, it is possible for a user to inject SQL functionality or statements by using specially built input such as (in this example) this password\: ' OR ''\='. In this case the statement becomes\:
advanced_1210_p=Which is always true no matter what the password stored in the database is. For more information about SQL Injection, see Glossary and Links.
advanced_1211_h3=Disabling Literals
advanced_1212_p=SQL Injection is not possible if user input is not directly embedded in SQL statements. A simple solution for the problem above is to use a PreparedStatement\:
advanced_1213_p=This database provides a way to enforce usage of parameters when passing user input to the database. This is done by disabling embedded literals in SQL statements. To do this, execute the statement\:
advanced_1214_p=Afterwards, SQL statements with text and number literals are not allowed any more. That means, SQL statement of the form WHERE NAME\='abc' or WHERE CustomerId\=10 will fail. It is still possible to use PreparedStatements and parameters as described above. Also, it is still possible to generate SQL statements dynamically, and use the Statement API, as long as the SQL statements do not include literals. There is also a second mode where number literals are allowed\: SET ALLOW_LITERALS NUMBERS. To allow all literals, execute SET ALLOW_LITERALS ALL (this is the default setting). Literals can only be enabled or disabled by an administrator.
advanced_1215_h3=Using Constants
advanced_1216_p=Disabling literals also means disabling hard-coded 'constant' literals. This database supports defining constants using the CREATE CONSTANT command. Constants can be defined only when literals are enabled, but used even when literals are disabled. To avoid name clashes with column names, constants can be defined in other schemas\:
advanced_1217_p=Even when literals are enabled, it is better to use constants instead of hard-coded number or text literals in queries or views. With constants, typos are found at compile time, the source code is easier to understand and change.
advanced_1218_h3=Using the ZERO() Function
advanced_1219_p=It is not required to create a constant for the number 0 as there is already a built-in function ZERO()\:
advanced_1220_h2=Restricting Class Loading and Usage
advanced_1221_p=By default there is no restriction on loading classes and executing Java code for admins. That means an admin may call system functions such as System.setProperty by executing\:
advanced_1222_p=To restrict users (including admins) from loading classes and executing code, the list of allowed classes can be set in the system property h2.allowedClasses in the form of a comma separated list of classes or patterns (items ending with '*'). By default all classes are allowed. Example\:
advanced_1223_p=This mechanism is used for all user classes, including database event listeners, trigger classes, user defined functions, user defined aggregate functions, and JDBC driver classes (with the exception of the H2 driver) when using the H2 Console.
advanced_1224_h2=Security Protocols
advanced_1225_p=The following paragraphs document the security protocols used in this database. These descriptions are very technical and only intended for security experts that already know the underlying security primitives.
advanced_1226_h3=User Password Encryption
advanced_1227_p=When a user tries to connect to a database, the combination of user name, @, and password hashed using SHA-256, and this hash value is transmitted to the database. This step does not try to an attacker from re-using the value if he is able to listen to the (unencrypted) transmission between the client and the server. But, the passwords are never transmitted as plain text, even when using an unencrypted connection between client and server. That means if a user reuses the same password for different things, this password is still protected up to some point. See also 'RFC 2617 - HTTP Authentication\: Basic and Digest Access Authentication' for more information.
advanced_1228_p=When a new database or user is created, a new cryptographically secure random salt value is generated. The size of the salt is 64 bit. Using the random salt reduces the risk of an attacker pre-calculating hash values for many different (commonly used) passwords.
advanced_1229_p=The combination of user-password hash value (see above) and salt is hashed using SHA-256. The resulting value is stored in the database. When a user tries to connect to the database, the database combines user-password hash value with the stored salt value and calculated the hash value. Other products use multiple iterations (hash the hash value again and again), but this is not done in this product to reduce the risk of denial of service attacks (where the attacker tries to connect with bogus passwords, and the server spends a lot of time calculating the hash value for each password). The reasoning is\: if the attacker has access to the hashed passwords, he also has access to the data in plain text, and therefore does not need the password any more. If the data is protected by storing it on another computer and only remotely, then the iteration count is not required at all.
advanced_1230_h3=File Encryption
advanced_1231_p=The database files can be encrypted using two different algorithms\: AES-128 and XTEA (using 32 rounds). The reasons for supporting XTEA is performance (XTEA is about twice as fast as AES) and to have an alternative algorithm if AES is suddenly broken.
advanced_1232_p=When a user tries to connect to an encrypted database, the combination of the word 'file', @, and the file password is hashed using SHA-256. This hash value is transmitted to the server.
advanced_1233_p=When a new database file is created, a new cryptographically secure random salt value is generated. The size of the salt is 64 bit. The combination of the file password hash and the salt value is hashed 1024 times using SHA-256. The reason for the iteration is to make it harder for an attacker to calculate hash values for common passwords.
advanced_1234_p=The resulting hash value is used as the key for the block cipher algorithm (AES-128 or XTEA with 32 rounds). Then, an initialization vector (IV) key is calculated by hashing the key again using SHA-256. This is to make sure the IV is unknown to the attacker. The reason for using a secret IV is to protect against watermark attacks.
advanced_1235_p=Before saving a block of data (each block is 8 bytes long), the following operations are executed\: First, the IV is calculated by encrypting the block number with the IV key (using the same block cipher algorithm). This IV is combined with the plain text using XOR. The resulting data is encrypted using the AES-128 or XTEA algorithm.
advanced_1236_p=When decrypting, the operation is done in reverse. First, the block is decrypted using the key, and then the IV is calculated combined with the decrypted text using XOR.
advanced_1237_p=Therefore, the block cipher modes of operation is CBC (Cipher-block chaining), but each chain is only one block long. The advantage over the ECB (Electronic codebook) mode is that patterns in the data are not revealed, and the advantage over multi block CBC is that flipped cipher text bits are not propagated to flipped plaintext bits in the next block.
advanced_1238_p=Database encryption is meant for securing the database while it is not in use (stolen laptop and so on). It is not meant for cases where the attacker has access to files while the database is in use. When he has write access, he can for example replace pieces of files with pieces of older versions and manipulate data like this.
advanced_1239_p=File encryption slows down the performance of the database engine. Compared to unencrypted mode, database operations take about 2.2 times longer when using XTEA, and 2.5 times longer using AES (embedded mode).
advanced_1240_h3=SSL/TLS Connections
advanced_1241_p=Remote SSL/TLS connections are supported using the Java Secure Socket Extension (SSLServerSocket / SSLSocket). By default, anonymous SSL is enabled. The default cipher suite is <code>SSL_DH_anon_WITH_RC4_128_MD5</code> .
advanced_1242_h3=HTTPS Connections
advanced_1243_p=The web server supports HTTP and HTTPS connections using SSLServerSocket. There is a default self-certified certificate to support an easy starting point, but custom certificates are supported as well.
advanced_1244_h2=Universally Unique Identifiers (UUID)
advanced_1245_p=This database supports the UUIDs. Also supported is a function to create new UUIDs using a cryptographically strong pseudo random number generator. With random UUIDs, the chance of two having the same value can be calculated using the probability theory. See also 'Birthday Paradox'. Standardized randomly generated UUIDs have 122 random bits. 4 bits are used for the version (Randomly generated UUID), and 2 bits for the variant (Leach-Salz). This database supports generating such UUIDs using the built-in function RANDOM_UUID(). Here is a small program to estimate the probability of having two identical UUIDs after generating a number of values\:
advanced_1246_p=Some values are\:
advanced_1247_p=To help non-mathematicians understand what those numbers mean, here a comparison\: One's annual risk of being hit by a meteorite is estimated to be one chance in 17 billion, that means the probability is about 0.000'000'000'06.
advanced_1248_h2=Settings Read from System Properties
advanced_1249_p=Some settings of the database can be set on the command line using -DpropertyName\=value. It is usually not required to change those settings manually. The settings are case sensitive. Example\:
advanced_1250_p=The current value of the settings can be read in the table INFORMATION_SCHEMA.SETTINGS.
advanced_1251_p=For a complete list of settings, see <a href\="../javadoc/org/h2/constant/SysProperties.html">SysProperties</a> .
advanced_1252_h2=Setting the Server Bind Address
advanced_1253_p=Usually server sockets accept connections on any/all local addresses. This may be a problem on multi-homed hosts. To bind only to one address, use the system property h2.bindAddress. This setting is used for both regular server sockets and for SSL server sockets. IPv4 and IPv6 address formats are supported.
advanced_1254_h2=Glossary and Links
advanced_1255_th=Term
advanced_1256_th=Description
advanced_1257_td=AES-128
advanced_1258_td=A block encryption algorithm. See also\: <a href\="http\://en.wikipedia.org/wiki/Advanced_Encryption_Standard">Wikipedia\: AES</a>
advanced_1259_td=Birthday Paradox
advanced_1260_td=Describes the higher than expected probability that two persons in a room have the same birthday. Also valid for randomly generated UUIDs. See also\: <a href\="http\://en.wikipedia.org/wiki/Birthday_paradox">Wikipedia\: Birthday Paradox</a>
advanced_1261_td=Digest
advanced_1262_td=Protocol to protect a password (but not to protect data). See also\: <a href\="http\://www.faqs.org/rfcs/rfc2617.html">RFC 2617\: HTTP Digest Access Authentication</a>
advanced_1263_td=GCJ
advanced_1264_td=GNU Compiler for Java. <a href\="http\://gcc.gnu.org/java/">http\://gcc.gnu.org/java/</a> and <a href\="http\://nativej.mtsystems.ch">http\://nativej.mtsystems.ch/ (not free any more)</a>
advanced_1265_td=HTTPS
advanced_1266_td=A protocol to provide security to HTTP connections. See also\: <a href\="http\://www.ietf.org/rfc/rfc2818.txt">RFC 2818\: HTTP Over TLS</a>
advanced_1267_td=Modes of Operation
advanced_1268_a=Wikipedia\: Block cipher modes of operation
advanced_1269_td=Salt
advanced_1270_td=Random number to increase the security of passwords. See also\: <a href\="http\://en.wikipedia.org/wiki/Key_derivation_function">Wikipedia\: Key derivation function</a>
advanced_1271_td=SHA-256
advanced_1272_td=A cryptographic one-way hash function. See also\: <a href\="http\://en.wikipedia.org/wiki/SHA_family">Wikipedia\: SHA hash functions</a>
advanced_1273_td=SQL Injection
advanced_1274_td=A security vulnerability where an application generates SQL statements with embedded user input. See also\: <a href\="http\://en.wikipedia.org/wiki/SQL_injection">Wikipedia\: SQL Injection</a>
advanced_1275_td=Watermark Attack
advanced_1276_td=Security problem of certain encryption programs where the existence of certain data can be proven without decrypting. For more information, search in the internet for 'watermark attack cryptoloop'
advanced_1277_td=SSL/TLS
advanced_1278_td=Secure Sockets Layer / Transport Layer Security. See also\: <a href\="http\://java.sun.com/products/jsse/">Java Secure Socket Extension (JSSE)</a>
advanced_1279_td=XTEA
advanced_1280_td=A block encryption algorithm. See also\: <a href\="http\://en.wikipedia.org/wiki/XTEA">Wikipedia\: XTEA</a>
advanced_1157_p=PostgreSQL ODBC Driver Setup requires a database password, that means it is not possible to connect to H2 databases without password. This is a limitation of the ODBC driver.
advanced_1158_h3=Security Considerations
advanced_1159_p=Currently, the PG Server does not support challenge response or encrypt passwords. This may be a problem if an attacker can listen to the data transferred between the ODBC driver and the server, because the password is readable to the attacker. Also, it is currently not possible to use encrypted SSL connections. Therefore the ODBC driver should not be used where security is important.
advanced_1160_h2=ACID
advanced_1161_p=In the database world, ACID stands for\:
advanced_1162_li=Atomicity\: Transactions must be atomic, meaning either all tasks are performed or none.
advanced_1163_li=Consistency\: All operations must comply with the defined constraints.
advanced_1164_li=Isolation\: Transactions must be isolated from each other.
advanced_1165_li=Durability\: Committed transaction will not be lost.
advanced_1166_h3=Atomicity
advanced_1167_p=Transactions in this database are always atomic.
advanced_1168_h3=Consistency
advanced_1169_p=This database is always in a consistent state. Referential integrity rules are always enforced.
advanced_1170_h3=Isolation
advanced_1171_p=For H2, as with most other database systems, the default isolation level is 'read committed'. This provides better performance, but also means that transactions are not completely isolated. H2 supports the transaction isolation levels 'serializable', 'read committed', and 'read uncommitted'.
advanced_1172_h3=Durability
advanced_1173_p=This database does not guarantee that all committed transactions survive a power failure. Tests show that all databases sometimes lose transactions on power failure (for details, see below). Where losing transactions is not acceptable, a laptop or UPS (uninterruptible power supply) should be used. If durability is required for all possible cases of hardware failure, clustering should be used, such as the H2 clustering mode.
advanced_1174_h2=Durability Problems
advanced_1175_p=Complete durability means all committed transaction survive a power failure. Some databases claim they can guarantee durability, but such claims are wrong. A durability test was run against H2, HSQLDB, PostgreSQL, and Derby. All of those databases sometimes lose committed transactions. The test is included in the H2 download, see org.h2.test.poweroff.Test.
advanced_1176_h3=Ways to (Not) Achieve Durability
advanced_1177_p=Making sure that committed transaction are not lost is more complicated than it seems first. To guarantee complete durability, a database must ensure that the log record is on the hard drive before the commit call returns. To do that, databases use different methods. One is to use the 'synchronous write' file access mode. In Java, RandomAccessFile supports the modes "rws" and "rwd"\:
advanced_1178_li=rwd\: Every update to the file's content is written synchronously to the underlying storage device.
advanced_1179_li=rws\: In addition to rwd, every update to the metadata is written synchronously.
advanced_1180_p=This feature is used by Derby. A test (org.h2.test.poweroff.TestWrite) with one of those modes achieves around 50 thousand write operations per second. Even when the operating system write buffer is disabled, the write rate is around 50 thousand operations per second. This feature does not force changes to disk because it does not flush all buffers. The test updates the same byte in the file again and again. If the hard drive was able to write at this rate, then the disk would need to make at least 50 thousand revolutions per second, or 3 million RPM (revolutions per minute). There are no such hard drives. The hard drive used for the test is about 7200 RPM, or about 120 revolutions per second. There is an overhead, so the maximum write rate must be lower than that.
advanced_1181_p=Buffers can be flushed by calling the function fsync. There are two ways to do that in Java\:
advanced_1182_li=FileDescriptor.sync(). The documentation says that this forces all system buffers to synchronize with the underlying device. Sync is supposed to return after all in-memory modified copies of buffers associated with this FileDescriptor have been written to the physical medium.
advanced_1183_li=FileChannel.force() (since JDK 1.4). This method is supposed to force any updates to this channel's file to be written to the storage device that contains it.
advanced_1184_p=By default, MySQL calls fsync for each commit. When using one of those methods, only around 60 write operations per second can be achieved, which is consistent with the RPM rate of the hard drive used. Unfortunately, even when calling FileDescriptor.sync() or FileChannel.force(), data is not always persisted to the hard drive, because most hard drives do not obey fsync()\: see 'Your Hard Drive Lies to You' at http\://hardware.slashdot.org/article.pl?sid\=05/05/13/0529252. In Mac OS X fsync does not flush hard drive buffers\: http\://lists.apple.com/archives/darwin-dev/2005/Feb/msg00072.html. So the situation is confusing, and tests prove there is a problem.
advanced_1185_p=Trying to flush hard drive buffers hard, and if you do the performance is very bad. First you need to make sure that the hard drive actually flushes all buffers. Tests show that this can not be done in a reliable way. Then the maximum number of transactions is around 60 per second. Because of those reasons, the default behavior of H2 is to delay writing committed transactions.
advanced_1186_p=In H2, after a power failure, a bit more than one second of committed transactions may be lost. To change the behavior, use SET WRITE_DELAY and CHECKPOINT SYNC. Most other databases support commit delay as well. In the performance comparison, commit delay was used for all databases that support it.
advanced_1187_h3=Running the Durability Test
advanced_1188_p=To test the durability / non-durability of this and other databases, you can use the test application in the package org.h2.test.poweroff. Two computers with network connection are required to run this test. One computer just listens, while the test application is run (and power is cut) on the other computer. The computer with the listener application opens a TCP/IP port and listens for an incoming connection. The second computer first connects to the listener, and then created the databases and starts inserting records. The connection is set to 'autocommit', which means after each inserted record a commit is performed automatically. Afterwards, the test computer notifies the listener that this record was inserted successfully. The listener computer displays the last inserted record number every 10 seconds. Now, switch off the power manually, then restart the computer, and run the application again. You will find out that in most cases, none of the databases contains all the records that the listener computer knows about. For details, please consult the source code of the listener and test application.
advanced_1189_h2=Using the Recover Tool
advanced_1190_p=The recover tool can be used to extract the contents of a data file, even if the database is corrupted. At this time, it does not extract the content of the log file or large objects (CLOB or BLOB). To run the tool, type on the command line\:
advanced_1191_p=For each database in the current directory, a text file will be created. This file contains raw insert statement (for the data) and data definition (DDL) statement to recreate the schema of the database. This file cannot be executed directly, as the raw insert statements don't have the correct table names, so the file needs to be pre-processed manually before executing.
advanced_1192_h2=File Locking Protocols
advanced_1193_p=Whenever a database is opened, a lock file is created to signal other processes that the database is in use. If database is closed, or if the process that opened the database terminates, this lock file is deleted.
advanced_1194_p=In special cases (if the process did not terminate normally, for example because there was a blackout), the lock file is not deleted by the process that created it. That means the existence of the lock file is not a safe protocol for file locking. However, this software uses a challenge-response protocol to protect the database files. There are two methods (algorithms) implemented to provide both security (that is, the same database files cannot be opened by two processes at the same time) and simplicity (that is, the lock file does not need to be deleted manually by the user). The two methods are 'file method' and 'socket methods'.
advanced_1195_h3=File Locking Method 'File'
advanced_1196_p=The default method for database file locking is the 'File Method'. The algorithm is\:
advanced_1197_li=When the lock file does not exist, it is created (using the atomic operation File.createNewFile). Then, the process waits a little bit (20ms) and checks the file again. If the file was changed during this time, the operation is aborted. This protects against a race condition when a process deletes the lock file just after one create it, and a third process creates the file again. It does not occur if there are only two writers.
advanced_1198_li=If the file can be created, a random number is inserted together with the locking method ('file'). Afterwards, a watchdog thread is started that checks regularly (every second once by default) if the file was deleted or modified by another (challenger) thread / process. Whenever that occurs, the file is overwritten with the old data. The watchdog thread runs with high priority so that a change to the lock file does not get through undetected even if the system is very busy. However, the watchdog thread does use very little resources (CPU time), because it waits most of the time. Also, the watchdog only reads from the hard disk and does not write to it.
advanced_1199_li=If the lock file exists, and it was modified in the 20 ms, the process waits for some time (up to 10 times). If it was still changed, an exception is thrown (database is locked). This is done to eliminate race conditions with many concurrent writers. Afterwards, the file is overwritten with a new version (challenge). After that, the thread waits for 2 seconds. If there is a watchdog thread protecting the file, he will overwrite the change and this process will fail to lock the database. However, if there is no watchdog thread, the lock file will still be as written by this thread. In this case, the file is deleted and atomically created again. The watchdog thread is started in this case and the file is locked.
advanced_1200_p=This algorithm is tested with over 100 concurrent threads. In some cases, when there are many concurrent threads trying to lock the database, they block each other (meaning the file cannot be locked by any of them) for some time. However, the file never gets locked by two threads at the same time. However using that many concurrent threads / processes is not the common use case. Generally, an application should throw an error to the user if it cannot open a database, and not try again in a (fast) loop.
advanced_1201_h3=File Locking Method 'Socket'
advanced_1202_p=There is a second locking mechanism implemented, but disabled by default. The algorithm is\:
advanced_1203_li=If the lock file does not exist, it is created. Then a server socket is opened on a defined port, and kept open. The port and IP address of the process that opened the database is written into the lock file.
advanced_1204_li=If the lock file exists, and the lock method is 'file', then the software switches to the 'file' method.
advanced_1205_li=If the lock file exists, and the lock method is 'socket', then the process checks if the port is in use. If the original process is still running, the port is in use and this process throws an exception (database is in use). If the original process died (for example due to a blackout, or abnormal termination of the virtual machine), then the port was released. The new process deletes the lock file and starts again.
advanced_1206_p=This method does not require a watchdog thread actively polling (reading) the same file every second. The problem with this method is, if the file is stored on a network share, two processes (running on different computers) could still open the same database files, if they do not have a direct TCP/IP connection.
advanced_1207_h2=Protection against SQL Injection
advanced_1208_h3=What is SQL Injection
advanced_1209_p=This database engine provides a solution for the security vulnerability known as 'SQL Injection'. Here is a short description of what SQL injection means. Some applications build SQL statements with embedded user input such as\:
advanced_1210_p=If this mechanism is used anywhere in the application, and user input is not correctly filtered or encoded, it is possible for a user to inject SQL functionality or statements by using specially built input such as (in this example) this password\: ' OR ''\='. In this case the statement becomes\:
advanced_1211_p=Which is always true no matter what the password stored in the database is. For more information about SQL Injection, see Glossary and Links.
advanced_1212_h3=Disabling Literals
advanced_1213_p=SQL Injection is not possible if user input is not directly embedded in SQL statements. A simple solution for the problem above is to use a PreparedStatement\:
advanced_1214_p=This database provides a way to enforce usage of parameters when passing user input to the database. This is done by disabling embedded literals in SQL statements. To do this, execute the statement\:
advanced_1215_p=Afterwards, SQL statements with text and number literals are not allowed any more. That means, SQL statement of the form WHERE NAME\='abc' or WHERE CustomerId\=10 will fail. It is still possible to use PreparedStatements and parameters as described above. Also, it is still possible to generate SQL statements dynamically, and use the Statement API, as long as the SQL statements do not include literals. There is also a second mode where number literals are allowed\: SET ALLOW_LITERALS NUMBERS. To allow all literals, execute SET ALLOW_LITERALS ALL (this is the default setting). Literals can only be enabled or disabled by an administrator.
advanced_1216_h3=Using Constants
advanced_1217_p=Disabling literals also means disabling hard-coded 'constant' literals. This database supports defining constants using the CREATE CONSTANT command. Constants can be defined only when literals are enabled, but used even when literals are disabled. To avoid name clashes with column names, constants can be defined in other schemas\:
advanced_1218_p=Even when literals are enabled, it is better to use constants instead of hard-coded number or text literals in queries or views. With constants, typos are found at compile time, the source code is easier to understand and change.
advanced_1219_h3=Using the ZERO() Function
advanced_1220_p=It is not required to create a constant for the number 0 as there is already a built-in function ZERO()\:
advanced_1221_h2=Restricting Class Loading and Usage
advanced_1222_p=By default there is no restriction on loading classes and executing Java code for admins. That means an admin may call system functions such as System.setProperty by executing\:
advanced_1223_p=To restrict users (including admins) from loading classes and executing code, the list of allowed classes can be set in the system property h2.allowedClasses in the form of a comma separated list of classes or patterns (items ending with '*'). By default all classes are allowed. Example\:
advanced_1224_p=This mechanism is used for all user classes, including database event listeners, trigger classes, user defined functions, user defined aggregate functions, and JDBC driver classes (with the exception of the H2 driver) when using the H2 Console.
advanced_1225_h2=Security Protocols
advanced_1226_p=The following paragraphs document the security protocols used in this database. These descriptions are very technical and only intended for security experts that already know the underlying security primitives.
advanced_1227_h3=User Password Encryption
advanced_1228_p=When a user tries to connect to a database, the combination of user name, @, and password hashed using SHA-256, and this hash value is transmitted to the database. This step does not try to an attacker from re-using the value if he is able to listen to the (unencrypted) transmission between the client and the server. But, the passwords are never transmitted as plain text, even when using an unencrypted connection between client and server. That means if a user reuses the same password for different things, this password is still protected up to some point. See also 'RFC 2617 - HTTP Authentication\: Basic and Digest Access Authentication' for more information.
advanced_1229_p=When a new database or user is created, a new cryptographically secure random salt value is generated. The size of the salt is 64 bit. Using the random salt reduces the risk of an attacker pre-calculating hash values for many different (commonly used) passwords.
advanced_1230_p=The combination of user-password hash value (see above) and salt is hashed using SHA-256. The resulting value is stored in the database. When a user tries to connect to the database, the database combines user-password hash value with the stored salt value and calculated the hash value. Other products use multiple iterations (hash the hash value again and again), but this is not done in this product to reduce the risk of denial of service attacks (where the attacker tries to connect with bogus passwords, and the server spends a lot of time calculating the hash value for each password). The reasoning is\: if the attacker has access to the hashed passwords, he also has access to the data in plain text, and therefore does not need the password any more. If the data is protected by storing it on another computer and only remotely, then the iteration count is not required at all.
advanced_1231_h3=File Encryption
advanced_1232_p=The database files can be encrypted using two different algorithms\: AES-128 and XTEA (using 32 rounds). The reasons for supporting XTEA is performance (XTEA is about twice as fast as AES) and to have an alternative algorithm if AES is suddenly broken.
advanced_1233_p=When a user tries to connect to an encrypted database, the combination of the word 'file', @, and the file password is hashed using SHA-256. This hash value is transmitted to the server.
advanced_1234_p=When a new database file is created, a new cryptographically secure random salt value is generated. The size of the salt is 64 bit. The combination of the file password hash and the salt value is hashed 1024 times using SHA-256. The reason for the iteration is to make it harder for an attacker to calculate hash values for common passwords.
advanced_1235_p=The resulting hash value is used as the key for the block cipher algorithm (AES-128 or XTEA with 32 rounds). Then, an initialization vector (IV) key is calculated by hashing the key again using SHA-256. This is to make sure the IV is unknown to the attacker. The reason for using a secret IV is to protect against watermark attacks.
advanced_1236_p=Before saving a block of data (each block is 8 bytes long), the following operations are executed\: First, the IV is calculated by encrypting the block number with the IV key (using the same block cipher algorithm). This IV is combined with the plain text using XOR. The resulting data is encrypted using the AES-128 or XTEA algorithm.
advanced_1237_p=When decrypting, the operation is done in reverse. First, the block is decrypted using the key, and then the IV is calculated combined with the decrypted text using XOR.
advanced_1238_p=Therefore, the block cipher modes of operation is CBC (Cipher-block chaining), but each chain is only one block long. The advantage over the ECB (Electronic codebook) mode is that patterns in the data are not revealed, and the advantage over multi block CBC is that flipped cipher text bits are not propagated to flipped plaintext bits in the next block.
advanced_1239_p=Database encryption is meant for securing the database while it is not in use (stolen laptop and so on). It is not meant for cases where the attacker has access to files while the database is in use. When he has write access, he can for example replace pieces of files with pieces of older versions and manipulate data like this.
advanced_1240_p=File encryption slows down the performance of the database engine. Compared to unencrypted mode, database operations take about 2.2 times longer when using XTEA, and 2.5 times longer using AES (embedded mode).
advanced_1241_h3=SSL/TLS Connections
advanced_1242_p=Remote SSL/TLS connections are supported using the Java Secure Socket Extension (SSLServerSocket / SSLSocket). By default, anonymous SSL is enabled. The default cipher suite is <code>SSL_DH_anon_WITH_RC4_128_MD5</code> .
advanced_1243_h3=HTTPS Connections
advanced_1244_p=The web server supports HTTP and HTTPS connections using SSLServerSocket. There is a default self-certified certificate to support an easy starting point, but custom certificates are supported as well.
advanced_1245_h2=Universally Unique Identifiers (UUID)
advanced_1246_p=This database supports the UUIDs. Also supported is a function to create new UUIDs using a cryptographically strong pseudo random number generator. With random UUIDs, the chance of two having the same value can be calculated using the probability theory. See also 'Birthday Paradox'. Standardized randomly generated UUIDs have 122 random bits. 4 bits are used for the version (Randomly generated UUID), and 2 bits for the variant (Leach-Salz). This database supports generating such UUIDs using the built-in function RANDOM_UUID(). Here is a small program to estimate the probability of having two identical UUIDs after generating a number of values\:
advanced_1247_p=Some values are\:
advanced_1248_p=To help non-mathematicians understand what those numbers mean, here a comparison\: One's annual risk of being hit by a meteorite is estimated to be one chance in 17 billion, that means the probability is about 0.000'000'000'06.
advanced_1249_h2=Settings Read from System Properties
advanced_1250_p=Some settings of the database can be set on the command line using -DpropertyName\=value. It is usually not required to change those settings manually. The settings are case sensitive. Example\:
advanced_1251_p=The current value of the settings can be read in the table INFORMATION_SCHEMA.SETTINGS.
advanced_1252_p=For a complete list of settings, see <a href\="../javadoc/org/h2/constant/SysProperties.html">SysProperties</a> .
advanced_1253_h2=Setting the Server Bind Address
advanced_1254_p=Usually server sockets accept connections on any/all local addresses. This may be a problem on multi-homed hosts. To bind only to one address, use the system property h2.bindAddress. This setting is used for both regular server sockets and for SSL server sockets. IPv4 and IPv6 address formats are supported.
advanced_1255_h2=Glossary and Links
advanced_1256_th=Term
advanced_1257_th=Description
advanced_1258_td=AES-128
advanced_1259_td=A block encryption algorithm. See also\: <a href\="http\://en.wikipedia.org/wiki/Advanced_Encryption_Standard">Wikipedia\: AES</a>
advanced_1260_td=Birthday Paradox
advanced_1261_td=Describes the higher than expected probability that two persons in a room have the same birthday. Also valid for randomly generated UUIDs. See also\: <a href\="http\://en.wikipedia.org/wiki/Birthday_paradox">Wikipedia\: Birthday Paradox</a>
advanced_1262_td=Digest
advanced_1263_td=Protocol to protect a password (but not to protect data). See also\: <a href\="http\://www.faqs.org/rfcs/rfc2617.html">RFC 2617\: HTTP Digest Access Authentication</a>
advanced_1264_td=GCJ
advanced_1265_td=GNU Compiler for Java. <a href\="http\://gcc.gnu.org/java/">http\://gcc.gnu.org/java/</a> and <a href\="http\://nativej.mtsystems.ch">http\://nativej.mtsystems.ch/ (not free any more)</a>
advanced_1266_td=HTTPS
advanced_1267_td=A protocol to provide security to HTTP connections. See also\: <a href\="http\://www.ietf.org/rfc/rfc2818.txt">RFC 2818\: HTTP Over TLS</a>
advanced_1268_td=Modes of Operation
advanced_1269_a=Wikipedia\: Block cipher modes of operation
advanced_1270_td=Salt
advanced_1271_td=Random number to increase the security of passwords. See also\: <a href\="http\://en.wikipedia.org/wiki/Key_derivation_function">Wikipedia\: Key derivation function</a>
advanced_1272_td=SHA-256
advanced_1273_td=A cryptographic one-way hash function. See also\: <a href\="http\://en.wikipedia.org/wiki/SHA_family">Wikipedia\: SHA hash functions</a>
advanced_1274_td=SQL Injection
advanced_1275_td=A security vulnerability where an application generates SQL statements with embedded user input. See also\: <a href\="http\://en.wikipedia.org/wiki/SQL_injection">Wikipedia\: SQL Injection</a>
advanced_1276_td=Watermark Attack
advanced_1277_td=Security problem of certain encryption programs where the existence of certain data can be proven without decrypting. For more information, search in the internet for 'watermark attack cryptoloop'
advanced_1278_td=SSL/TLS
advanced_1279_td=Secure Sockets Layer / Transport Layer Security. See also\: <a href\="http\://java.sun.com/products/jsse/">Java Secure Socket Extension (JSSE)</a>
advanced_1280_td=XTEA
advanced_1281_td=A block encryption algorithm. See also\: <a href\="http\://en.wikipedia.org/wiki/XTEA">Wikipedia\: XTEA</a>
build_1000_h1=Build
build_1001_a=Portability
build_1002_a=Environment
......@@ -866,7 +867,7 @@ history_1030_li=Jun Iyama, Japan
history_1031_li=Antonio Casqueiro, Portugal
history_1032_li=lumber-mill.co.jp, Japan
history_1033_li=Oliver Computing LLC, USA
history_1034_li=Harpal Grover, USA
history_1034_li=Harpal Grover Consulting Inc., USA
installation_1000_h1=Installation
installation_1001_a=Requirements
installation_1002_a=Supported Platforms
......
......@@ -53,6 +53,7 @@ login.connect=Connect
login.driverClass=Driver Class
login.driverNotFound=Database driver not found<br />See in the Help for how to add drivers
login.goAdmin=Preferences
login.goTools=Tools
login.jdbcUrl=JDBC URL
login.language=Language
login.login=Login
......
......@@ -4,6 +4,7 @@
*/
package org.h2.constant;
/**
* This class defines the error codes used for SQL exceptions.
*/
......@@ -245,9 +246,6 @@ public class ErrorCode {
*/
public static final int COLUMN_NOT_FOUND_1 = 42122;
public static final int SETTING_NOT_FOUND_1 = 42132;
// 0A: feature not supported
// HZ: remote database access
......@@ -509,6 +507,15 @@ public class ErrorCode {
* </pre>
*/
public static final int TRACE_CONNECTION_NOT_CLOSED = 90018;
/**
* The error with code <code>90019</code> is thrown when
* trying to drop the current user.
* Example:
* <pre>
* DROP USER SA;
* </pre>
*/
public static final int CANNOT_DROP_CURRENT_USER = 90019;
/**
......@@ -541,8 +548,32 @@ public class ErrorCode {
* </pre>
*/
public static final int DATA_CONVERSION_ERROR_1 = 90021;
/**
* The error with code <code>90022</code> is thrown when
* trying to call a unknown function.
* Example:
* <pre>
* CALL SPECIAL_SIN(10);
* </pre>
*/
public static final int FUNCTION_NOT_FOUND_1 = 90022;
/**
* The error with code <code>90023</code> is thrown when
* trying to set a primary key on a nullable column.
* Example:
* <pre>
* CREATE TABLE TEST(ID INT, NAME VARCHAR);
* ALTER TABLE TEST ADD CONSTRAINT PK PRIMARY KEY(ID);
* </pre>
*/
public static final int COLUMN_MUST_NOT_BE_NULLABLE_1 = 90023;
/**
* The error with code <code>90024</code> is thrown when
* a file could not be renamed.
*/
public static final int FILE_RENAME_FAILED_2 = 90024;
/**
......@@ -551,7 +582,17 @@ public class ErrorCode {
* (only in Windows), or because an error occured when deleting.
*/
public static final int FILE_DELETE_FAILED_1 = 90025;
/**
* The error with code <code>90026</code> is thrown when
* an object could not be serialized.
*/
public static final int SERIALIZATION_FAILED_1 = 90026;
/**
* The error with code <code>90027</code> is thrown when
* an object could not be de-serialized.
*/
public static final int DESERIALIZATION_FAILED_1 = 90027;
/**
......@@ -560,8 +601,33 @@ public class ErrorCode {
* cause of the exception.
*/
public static final int IO_EXCEPTION_1 = 90028;
/**
* The error with code <code>90029</code> is thrown when
* calling ResultSet.deleteRow(), insertRow(), or updateRow()
* when the current row is not updatable.
* Example:
* <pre>
* ResultSet rs = stat.executeQuery("SELECT * FROM TEST");
* rs.next();
* rs.insertRow();
* </pre>
*/
public static final int NOT_ON_UPDATABLE_ROW = 90029;
/**
* The error with code <code>90030</code> is thrown when
* the database engine has detected a checksum mismatch in the data
* or index. To solve this problem, restore a backup or use the
* Recovery tool (org.h2.tools.Recover).
*/
public static final int FILE_CORRUPTED_1 = 90030;
/**
* The error with code <code>90031</code> is thrown when
* an input / output error occured. For more information, see the root
* cause of the exception.
*/
public static final int IO_EXCEPTION_2 = 90031;
/**
......@@ -569,13 +635,50 @@ public class ErrorCode {
* trying to drop or alter a user that does not exist.
* Example:
* <pre>
* DROP USER TESTUSER;
* DROP USER TEST_USER;
* </pre>
*/
public static final int USER_NOT_FOUND_1 = 90032;
/**
* The error with code <code>90033</code> is thrown when
* trying to create a user or role if a user with this name already exists.
* Example:
* <pre>
* CREATE USER TEST_USER;
* CREATE USER TEST_USER;
* </pre>
*/
public static final int USER_ALREADY_EXISTS_1 = 90033;
public static final int LOG_FILE_ERROR_2 = 90034;
/**
* The error with code <code>90034</code> is thrown when
* writing to the trace file failed, for example because the there
* is an I/O exception. This message is printed to System.out,
* but only once.
*/
public static final int TRACE_FILE_ERROR_2 = 90034;
/**
* The error with code <code>90035</code> is thrown when
* trying to create a sequence if a sequence with this name already
* exists.
* Example:
* <pre>
* CREATE SEQUENCE TEST_SEQ;
* CREATE SEQUENCE TEST_SEQ;
* </pre>
*/
public static final int SEQUENCE_ALREADY_EXISTS_1 = 90035;
/**
* The error with code <code>90036</code> is thrown when
* trying to access a sequence that does not exist.
* Example:
* <pre>
* SELECT NEXT VALUE FOR SEQUENCE XYZ;
* </pre>
*/
public static final int SEQUENCE_NOT_FOUND_1 = 90036;
/**
......@@ -587,15 +690,81 @@ public class ErrorCode {
* </pre>
*/
public static final int VIEW_NOT_FOUND_1 = 90037;
/**
* The error with code <code>90038</code> is thrown when
* trying to create a view if a view with this name already
* exists.
* Example:
* <pre>
* CREATE VIEW DUMMY AS SELECT * FROM DUAL;
* CREATE VIEW DUMMY AS SELECT * FROM DUAL;
* </pre>
*/
public static final int VIEW_ALREADY_EXISTS_1 = 90038;
/**
* The error with code <code>90039</code> is thrown when
* trying to convert a decimal value to lower precision if the
* value is out of range for this precision.
* Example:
* <pre>
* SELECT * FROM TABLE(X DECIMAL(2, 2) = (123.34));
* </pre>
*/
public static final int VALUE_TOO_LARGE_FOR_PRECISION_1 = 90039;
/**
* The error with code <code>90040</code> is thrown when
* a user that is not administrator tries to execute a statement
* that requires admin privileges.
*/
public static final int ADMIN_RIGHTS_REQUIRED = 90040;
/**
* The error with code <code>90041</code> is thrown when
* trying to create a trigger and there is already a trigger with that name.
* <pre>
* CREATE TABLE TEST(ID INT);
* CREATE TRIGGER TRIGGER_A AFTER INSERT ON TEST
* CALL "org.h2.samples.TriggerSample$MyTrigger";
* CREATE TRIGGER TRIGGER_A AFTER INSERT ON TEST
* CALL "org.h2.samples.TriggerSample$MyTrigger";
* </pre>
*/
public static final int TRIGGER_ALREADY_EXISTS_1 = 90041;
/**
* The error with code <code>90042</code> is thrown when
* trying to drop a trigger that does not exist.
* Example:
* <pre>
* DROP TRIGGER TRIGGER_XYZ;
* </pre>
*/
public static final int TRIGGER_NOT_FOUND_1 = 90042;
private int test;
public static final int ERROR_CREATING_TRIGGER_OBJECT_3 = 90043;
public static final int ERROR_EXECUTING_TRIGGER_3 = 90044;
public static final int CONSTRAINT_ALREADY_EXISTS_1 = 90045;
/**
* The error with code <code>90046</code> is thrown when
* trying to open a connection to a database using an unsupported URL format.
* Please see the documentation on the supported URL format and examples.
* Example:
* <pre>
* jdbc:h2:;;
* </pre>
*/
public static final int URL_FORMAT_ERROR_2 = 90046;
/**
* The error with code <code>90047</code> is thrown when
* trying to connect to a TCP server with an incompatible client.
*/
public static final int DRIVER_VERSION_ERROR_2 = 90047;
public static final int FILE_VERSION_ERROR_1 = 90048;
......@@ -1025,7 +1194,6 @@ public class ErrorCode {
case INDEX_NOT_FOUND_1: return "42S12";
case DUPLICATE_COLUMN_NAME_1: return "42S21";
case COLUMN_NOT_FOUND_1: return "42S22";
case SETTING_NOT_FOUND_1: return "42S32";
// 0A: feature not supported
......
......@@ -26,6 +26,11 @@ public class SysProperties {
*/
public static final String H2_MAX_QUERY_TIMEOUT = "h2.maxQueryTimeout";
/**
* INTERNAL
*/
public static final String H2_LOG_DELETE_DELAY = "h2.logDeleteDelay";
/**
* System property <code>file.encoding</code> (default: Cp1252).<br />
* It is usually set by the system and is the default encoding used for the RunScript and CSV tool.
......@@ -384,4 +389,10 @@ public class SysProperties {
return getIntSetting(H2_MAX_QUERY_TIMEOUT, 0);
}
/**
* INTERNAL
*/
public static int getLogFileDeleteDelay() {
return getIntSetting(H2_LOG_DELETE_DELAY, 500);
}
}
......@@ -1343,6 +1343,14 @@ public class Database implements DataHandler {
}
}
public void deleteLogFileLater(String fileName) throws SQLException {
if (writer == null) {
FileUtils.delete(fileName);
} else {
writer.deleteLater(fileName);
}
}
public Class loadUserClass(String className) throws SQLException {
try {
return ClassUtils.loadUserClass(className);
......
......@@ -390,7 +390,7 @@ public class LogFile {
file.close();
file = null;
if (delete) {
FileUtils.delete(fileName);
database.deleteLogFileLater(fileName);
}
} catch (IOException e) {
if (closeException == null) {
......
......@@ -195,7 +195,7 @@ public class TraceSystem {
}
writingErrorLogged = true;
// TODO translate trace messages
SQLException se = Message.getSQLException(ErrorCode.LOG_FILE_ERROR_2, new String[] { fileName, e.toString() },
SQLException se = Message.getSQLException(ErrorCode.TRACE_FILE_ERROR_2, new String[] { fileName, e.toString() },
e);
// print this error only once
fileName = null;
......
......@@ -41,6 +41,7 @@ public class DbStarter implements ServletContextListener {
if (serverParams != null) {
String[] params = StringUtils.arraySplit(serverParams, ' ', true);
server = Server.createTcpServer(params);
server.start();
}
// To access the database using the server, use the URL:
// jdbc:h2:tcp://localhost/~/test
......
......@@ -949,7 +949,7 @@ class WebThread extends Thread implements DatabaseEventListener {
class LoginTask implements Runnable, DatabaseEventListener {
private DataOutputStream output;
private PrintWriter writer;
SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss.SSS");
private SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss.SSS");
LoginTask() throws IOException {
String message = "HTTP/1.1 200 OK\n";
......@@ -974,6 +974,7 @@ class WebThread extends Thread implements DatabaseEventListener {
public void exceptionThrown(SQLException e, String sql) {
log("Exception: " + PageParser.escapeHtml(e.toString()) + " SQL: " + PageParser.escapeHtml(sql));
server.traceError(e);
}
public void init(String url) {
......@@ -1019,6 +1020,7 @@ class WebThread extends Thread implements DatabaseEventListener {
writer.println(message + "<br />");
writer.flush();
}
server.trace(message);
}
public void run() {
......
......@@ -53,6 +53,7 @@ login.connect=Verbinden
login.driverClass=Datenbank-Treiber Klasse
login.driverNotFound=Datenbank-Treiber nicht gefunden<br />F&uuml;r Informationen zum Hinzuf&uuml;gen von Treibern siehe Hilfe
login.goAdmin=Optionen
login.goTools=\#Tools
login.jdbcUrl=JDBC URL
login.language=Sprache
login.login=Login
......
......@@ -53,6 +53,7 @@ login.connect=Conectar
login.driverClass=Controlador
login.driverNotFound=Controlador no encontrado
login.goAdmin=Preferencias
login.goTools=\#Tools
login.jdbcUrl=URL JDBC
login.language=Idioma
login.login=Registrar
......
......@@ -53,6 +53,7 @@ login.connect=Connecter
login.driverClass=Pilote JDBC
login.driverNotFound=Driver non trouv&eacute;.<br />Veuillez consulter dans l'aide la proc&eacute;dure d'ajout de drivers.
login.goAdmin=Options
login.goTools=\#Tools
login.jdbcUrl=URL JDBC
login.language=Langue
login.login=Connexion
......
......@@ -53,6 +53,7 @@ login.connect=Csatlakoz&aacute;s
login.driverClass=Illeszt&\#337;program oszt&aacute;ly
login.driverNotFound=Adatb&aacute;zis-illeszt&\#337;program nem tal&aacute;lhat&oacute;&lt;br&gt;Illeszt&\#337;programok hozz&aacute;ad&aacute;s&aacute;r&oacute;l a S&uacute;g&oacute; ad felvil&aacute;gos&iacute;t&aacute;st.
login.goAdmin=Tulajdons&aacute;gok
login.goTools=\#Tools
login.jdbcUrl=JDBC URL
login.language=Nyelv
login.login=Bel&eacute;p&eacute;s
......
......@@ -53,6 +53,7 @@ login.connect=Hubungkan
login.driverClass=Kelas Pengendali
login.driverNotFound=Pengendali basis data tidak ditemukan<br />Pelajari bagian Bantuan untuk mengetahui bagaimana cara menambah pengendali basis data
login.goAdmin=Pilihan
login.goTools=\#Tools
login.jdbcUrl=JDBC URL
login.language=Bahasa
login.login=Login
......
......@@ -53,6 +53,7 @@ login.connect=Connetti
login.driverClass=Classe driver
login.driverNotFound=Il driver del database non \u00E8 stato trovato<br />Guardare in Aiuto su come aggiungere dei drivers
login.goAdmin=Preferenze
login.goTools=\#Tools
login.jdbcUrl=JDBC URL
login.language=Lingua
login.login=Accesso
......
......@@ -53,6 +53,7 @@ login.connect=\u63A5\u7D9A
login.driverClass=\u30C9\u30E9\u30A4\u30D0\u30AF\u30E9\u30B9
login.driverNotFound=\u30C7\u30FC\u30BF\u30D9\u30FC\u30B9\u30C9\u30E9\u30A4\u30D0\u304C\u898B\u4ED8\u304B\u308A\u307E\u305B\u3093<br />\u30D8\u30EB\u30D7\u3067\u30C9\u30E9\u30A4\u30D0\u306E\u8FFD\u52A0\u65B9\u6CD5\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044
login.goAdmin=\u8A2D\u5B9A
login.goTools=\#Tools
login.jdbcUrl=JDBC URL
login.language=\u8A00\u8A9E
login.login=\u30ED\u30B0\u30A4\u30F3
......
......@@ -53,6 +53,7 @@ login.connect=Po&\#322;&\#261;cz
login.driverClass=Klasa sterownika
login.driverNotFound=Sterownik nie istnieje&lt;br /&gt;Zobacz w dokumentacji opis dodawania sterownik&oacute;w
login.goAdmin=Opcje
login.goTools=\#Tools
login.jdbcUrl=JDBC URL
login.language=J&\#281;zyk
login.login=U&\#380;ytkownik
......
......@@ -53,6 +53,7 @@ login.connect=Conectar
login.driverClass=Classe com o driver
login.driverNotFound=O driver n&atilde;o foi encontrado&lt;br/&gt;Ver na se&ccedil;&atilde;o de ajuda, como adicionar drivers
login.goAdmin=Prefer&ecirc;ncias
login.goTools=\#Tools
login.jdbcUrl=JDBC URL
login.language=L&iacute;ngua
login.login=Login
......
......@@ -53,6 +53,7 @@ login.connect=Estabelecer conex&atilde;o
login.driverClass=Classe com o driver
login.driverNotFound=O driver n&atilde;o foi encontrado&lt;br/&gt;Ver na sec&ccedil;&atilde;o de ajuda, como adicionar drivers
login.goAdmin=Preferencias
login.goTools=\#Tools
login.jdbcUrl=JDBC URL
login.language=Lingua
login.login=Login
......
......@@ -53,6 +53,7 @@ login.connect=&\#1057;&\#1086;&\#1077;&\#1076;&\#1080;&\#1085;&\#1080;&\#1090;&\
login.driverClass=&\#1050;&\#1083;&\#1072;&\#1089;&\#1089; &\#1076;&\#1088;&\#1072;&\#1081;&\#1074;&\#1077;&\#1088;&\#1072;
login.driverNotFound=&\#1044;&\#1088;&\#1072;&\#1081;&\#1074;&\#1077;&\#1088; &\#1073;&\#1072;&\#1079;&\#1099; &\#1076;&\#1072;&\#1085;&\#1085;&\#1099;&\#1093; &\#1085;&\#1077; &\#1085;&\#1072;&\#1081;&\#1076;&\#1077;&\#1085;&lt;br /&gt;&\#1055;&\#1086;&\#1089;&\#1084;&\#1086;&\#1090;&\#1088;&\#1080;&\#1090;&\#1077; &\#1074; &\#1055;&\#1086;&\#1084;&\#1086;&\#1097;&\#1080;, &\#1082;&\#1072;&\#1082; &\#1076;&\#1086;&\#1073;&\#1072;&\#1074;&\#1080;&\#1090;&\#1100; &\#1076;&\#1088;&\#1072;&\#1081;&\#1074;&\#1077;&\#1088; &\#1073;&\#1072;&\#1079;&\#1099; &\#1076;&\#1072;&\#1085;&\#1085;&\#1099;&\#1093;
login.goAdmin=Preferences
login.goTools=\#Tools
login.jdbcUrl=JDBC URL
login.language=&\#1071;&\#1079;&\#1099;&\#1082;
login.login=&\#1051;&\#1086;&\#1075;&\#1080;&\#1085;
......
......@@ -53,6 +53,7 @@ login.connect=Ba&\#287;lan
login.driverClass=Veri taban&\#305; s&\#252;r&\#252;c&\#252; s&\#305;n&\#305;f&\#305;
login.driverNotFound=&\#304;stenilen veri taban&\#305; s&\#252;r&\#252;c&\#252;s&\#252; bulunamad&\#305;<br />S&\#252;r&\#252;c&\#252; ekleme konusunda bilgi i&\#231;in Yard&\#305;m'a ba&\#351;vurunuz
login.goAdmin=Se&\#231;enekler
login.goTools=\#Tools
login.jdbcUrl=JDBC URL
login.language=Dil
login.login=Gir
......
......@@ -53,6 +53,7 @@ login.connect=&\#x041F;&\#x0456;&\#x0434;'&\#x0454;&\#x0434;&\#x043D;&\#x0430;&\
login.driverClass=Driver Class
login.driverNotFound=&\#x0414;&\#x0440;&\#x0430;&\#x0432;&\#x0435;&\#x0440; &\#x0431;&\#x0430;&\#x0437;&\#x0438; &\#x0434;&\#x0430;&\#x043D;&\#x0438;&\#x0445; &\#x043D;&\#x0435; &\#x0437;&\#x043D;&\#x0430;&\#x0439;&\#x0434;&\#x0435;&\#x043D;&\#x043E;<br />&\#x041F;&\#x043E;&\#x0434;&\#x0438;&\#x0432;&\#x0456;&\#x0442;&\#x044C;&\#x0441;&\#x044F; &\#x0432; &\#x0434;&\#x043E;&\#x043F;&\#x043E;&\#x043C;&\#x043E;&\#x0437;&\#x0456; &\#x044F;&\#x043A; &\#x0434;&\#x043E;&\#x0434;&\#x0430;&\#x0442;&\#x0438; &\#x043D;&\#x043E;&\#x0432;&\#x0456; &\#x0434;&\#x0440;&\#x0430;&\#x0439;&\#x0432;&\#x0435;&\#x0440;&\#x0438;
login.goAdmin=&\#x041D;&\#x0430;&\#x0441;&\#x0442;&\#x0440;&\#x043E;&\#x0439;&\#x043A;&\#x0438;
login.goTools=\#Tools
login.jdbcUrl=JDBC URL
login.language=&\#x041C;&\#x043E;&\#x0432;&\#x0430;
login.login=&\#x041B;&\#x043E;&\#x0433;&\#x0456;&\#x043D;
......
......@@ -53,6 +53,7 @@ login.connect=\u8FDE\u63A5
login.driverClass=\u9A71\u52A8\u7C7B
login.driverNotFound=\u6570\u636E\u5E93\u9A71\u52A8\u6CA1\u6709\u53D1\u73B0<br />\u8BF7\u53C2\u8003\u5E2E\u52A9\u53BB\u6DFB\u52A0\u6570\u636E\u5E93\u9A71\u52A8
login.goAdmin=\u914D\u7F6E
login.goTools=\#Tools
login.jdbcUrl=JDBC URL
login.language=\u8BED\u8A00
login.login=\u767B\u5F55
......
......@@ -6,6 +6,9 @@ package org.h2.store;
import java.lang.ref.WeakReference;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map.Entry;
import org.h2.constant.SysProperties;
import org.h2.engine.Constants;
......@@ -16,23 +19,80 @@ import org.h2.log.LogSystem;
import org.h2.message.Trace;
import org.h2.message.TraceSystem;
import org.h2.table.Table;
import org.h2.util.FileUtils;
import org.h2.util.ObjectArray;
import org.h2.util.ObjectUtils;
import org.h2.util.TempFileDeleter;
/**
* The writer thread is responsible to flush the transaction log file from time to time.
*/
public class WriterThread extends Thread {
// Thread objects are not garbage collected
// until they returned from the run() method
// (even if they where never started)
// so if the connection was not closed,
// the database object cannot get reclaimed
// by the garbage collector if we use a hard reference
/**
* The reference to the database.
*
* Thread objects are not garbage collected
* until they returned from the run() method
* (even if they where never started)
* so if the connection was not closed,
* the database object cannot get reclaimed
* by the garbage collector if we use a hard reference.
*/
private volatile WeakReference databaseRef;
private int writeDelay;
private long lastIndexFlush;
private volatile boolean stop;
private HashMap deleteLater = new HashMap();
private volatile long deleteNext;
public void deleteLater(String fileName) {
long at = System.currentTimeMillis() + SysProperties.getLogFileDeleteDelay();
if (at < deleteNext || deleteNext == 0) {
deleteNext = at;
}
synchronized (deleteLater) {
deleteLater.put(fileName, ObjectUtils.getLong(at));
}
}
private void delete(boolean now) {
if (!now && (deleteNext == 0 || System.currentTimeMillis() < deleteNext)) {
return;
}
long time = System.currentTimeMillis();
ObjectArray delete = new ObjectArray();
synchronized (deleteLater) {
deleteNext = 0;
for (Iterator it = deleteLater.entrySet().iterator(); it.hasNext();) {
Entry entry = (Entry) it.next();
long at = ((Long) entry.getValue()).longValue();
if (now || time >= at) {
String fileName = (String) entry.getKey();
delete.add(fileName);
} else {
if (at < deleteNext || deleteNext == 0) {
deleteNext = at;
}
}
}
}
for (int i = 0; i < delete.size(); i++) {
String fileName = (String) delete.get(i);
try {
FileUtils.delete(fileName);
synchronized (deleteLater) {
deleteLater.remove(fileName);
}
} catch (SQLException e) {
Database database = (Database) databaseRef.get();
if (database != null) {
database.getTrace(Trace.DATABASE).error("delete " + fileName, e);
}
}
}
}
private WriterThread(Database database, int writeDelay) {
this.databaseRef = new WeakReference(database);
......@@ -101,6 +161,7 @@ public class WriterThread extends Thread {
public void run() {
while (!stop) {
delete(false);
TempFileDeleter.deleteUnused();
Database database = (Database) databaseRef.get();
if (database == null) {
......@@ -135,6 +196,7 @@ public class WriterThread extends Thread {
}
public void stopThread() {
delete(true);
stop = true;
}
......
......@@ -149,16 +149,25 @@ java org.h2.test.TestAll timer
TestAll test = new TestAll();
test.printSystem();
/*
integrate tools in H2 Console
// TestRecover.main(new String[0]);
for all tools: add link to javadoc (like Recover)
/*
Automate real power off tests
Extend tests that simulate power off
timer test
DbStarter: server.start();
add test case!
java org.h2.tool.Server -baseDir C:\temp\test
web console: jdbc:h2:~/test
C:\temp\test\~
C:\temp\crash_db
- try delayed log file delete
integrate tools in H2 Console
for all tools: add link to javadoc (like Recover)
recovery tool: bad blocks should be converted to INSERT INTO SYSTEM_ERRORS(...),
and things should go into the .trace.db file
......@@ -167,14 +176,7 @@ RECOVER=2 to backup the database, run recovery, open the database
Recovery should work with encrypted databases
java org.h2.tool.Server -baseDir C:\temp\dbtest
web console: jdbc:h2:~/chin
C:\temp\dbtest\~
Automate real power off tests
Adjust cache memory usage
Extend tests that simulate power off
timer test
// test with garbage at the end of the log file (must be consistently detected as such)
// TestRandomSQL is too random; most statements fails
// extend the random join test that compared the result against PostgreSQL
......@@ -185,10 +187,15 @@ Test Recovery with MAX_LOG_FILE_SIZE=1; test with various log file sizes
Test with many columns (180), create index
add a 'kill process while altering tables' test case
SysProperties: change everything to H2_...
Use FilterIn / FilterOut putStream
Roadmap:
History:
Old log files are now deleted a bit after a new log file is created. This helps recovery.
The DbStarter servlet didn't start the TCP listener even if configured.
Statement.setQueryTimeout() is now supported. New session setting QUERY_TIMEOUT, and new system property h2.maxQueryTimeout.
Changing the transaction log level (SET LOG) is now written to the trace file by default.
In a SQL script, primary key constraints are now ordered before foreign key constraints.
......@@ -490,6 +497,7 @@ It was not possible to create a referential constraint to a table in a different
new TestReader().runTest(this);
new TestSampleApps().runTest(this);
new TestScriptReader().runTest(this);
runTest("org.h2.test.unit.TestServlet");
new TestSecurity().runTest(this);
new TestStreams().runTest(this);
new TestStringCache().runTest(this);
......@@ -502,6 +510,17 @@ It was not possible to create a referential constraint to a table in a different
afterTest();
}
private void runTest(String className) {
try {
Class clazz = Class.forName(className);
TestBase test = (TestBase) clazz.newInstance();
test.runTest(this);
} catch (Exception e) {
// ignore
TestBase.logError("Class not found: " + className, null);
}
}
public void beforeTest() throws SQLException {
DeleteDbFiles.execute(TestBase.baseDir, null, true);
FileSystemDisk.getInstance().deleteRecursive("trace.db");
......
......@@ -38,6 +38,7 @@ public class TestUpdatableResultSet extends TestBase {
stat.execute("INSERT INTO TEST VALUES(1, 'Hello'), (2, 'World'), (3, 'Test')");
ResultSet rs = stat.executeQuery("SELECT * FROM TEST ORDER BY ID");
check(rs.isBeforeFirst());
checkFalse(rs.isAfterLast());
check(rs.getRow(), 0);
......@@ -49,6 +50,14 @@ public class TestUpdatableResultSet extends TestBase {
check(rs.getRow(), 1);
rs.next();
try {
rs.insertRow();
error("Unexpected success");
} catch (SQLException e) {
checkNotGeneralException(e);
}
checkFalse(rs.isBeforeFirst());
checkFalse(rs.isAfterLast());
check(rs.getInt(1), 2);
......
/*
* Copyright 2004-2008 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.test.unit;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Properties;
import java.util.Set;
import javax.servlet.RequestDispatcher;
import javax.servlet.Servlet;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletException;
import org.h2.server.web.DbStarter;
import org.h2.test.TestBase;
/**
* Tests the DbStarter servlet.
* This test simulates a minimum servlet container environment.
*/
public class TestServlet extends TestBase {
/**
* Minimum ServletContext implementation.
* Most methods are not implemented.
*/
private static class TestServletContext implements ServletContext {
private Properties initParams = new Properties();
private HashMap attributes = new HashMap();
public void setAttribute(String key, Object value) {
attributes.put(key, value);
}
public Object getAttribute(String key) {
return attributes.get(key);
}
private void setInitParameter(String key, String value) {
initParams.setProperty(key, value);
}
public String getInitParameter(String key) {
return initParams.getProperty(key);
}
public Enumeration getAttributeNames() {
throw new UnsupportedOperationException();
}
public ServletContext getContext(String string) {
throw new UnsupportedOperationException();
}
public Enumeration getInitParameterNames() {
throw new UnsupportedOperationException();
}
public int getMajorVersion() {
throw new UnsupportedOperationException();
}
public String getMimeType(String string) {
throw new UnsupportedOperationException();
}
public int getMinorVersion() {
throw new UnsupportedOperationException();
}
public RequestDispatcher getNamedDispatcher(String string) {
throw new UnsupportedOperationException();
}
public String getRealPath(String string) {
throw new UnsupportedOperationException();
}
public RequestDispatcher getRequestDispatcher(String string) {
throw new UnsupportedOperationException();
}
public URL getResource(String string) throws MalformedURLException {
throw new UnsupportedOperationException();
}
public InputStream getResourceAsStream(String string) {
throw new UnsupportedOperationException();
}
public Set getResourcePaths(String string) {
throw new UnsupportedOperationException();
}
public String getServerInfo() {
throw new UnsupportedOperationException();
}
public Servlet getServlet(String string) throws ServletException {
throw new UnsupportedOperationException();
}
public String getServletContextName() {
throw new UnsupportedOperationException();
}
public Enumeration getServletNames() {
throw new UnsupportedOperationException();
}
public Enumeration getServlets() {
throw new UnsupportedOperationException();
}
public void log(String string) {
throw new UnsupportedOperationException();
}
public void log(Exception exception, String string) {
throw new UnsupportedOperationException();
}
public void log(String string, Throwable throwable) {
throw new UnsupportedOperationException();
}
public void removeAttribute(String string) {
throw new UnsupportedOperationException();
}
};
public void test() throws Exception {
DbStarter listener = new DbStarter();
TestServletContext context = new TestServletContext();
context.setInitParameter("db.url", getURL("servlet", true));
context.setInitParameter("db.user", getUser());
context.setInitParameter("db.password", getPassword());
context.setInitParameter("db.tcpServer", "-tcpPort 8888");
ServletContextEvent event = new ServletContextEvent(context);
listener.contextInitialized(event);
Connection conn1 = listener.getConnection();
Connection conn1a = (Connection) context.getAttribute("connection");
check(conn1 == conn1a);
Statement stat1 = conn1.createStatement();
stat1.execute("CREATE TABLE T(ID INT)");
Connection conn2 = DriverManager.getConnection("jdbc:h2:tcp://localhost:8888/" + baseDir + "/servlet", getUser(), getPassword());
Statement stat2 = conn2.createStatement();
stat2.execute("SELECT * FROM T");
stat2.execute("DROP TABLE T");
try {
stat1.execute("SELECT * FROM T");
error("Unexpected success");
} catch (SQLException e) {
checkNotGeneralException(e);
}
conn2.close();
listener.contextDestroyed(event);
// listener must be stopped
try {
conn2 = DriverManager.getConnection("jdbc:h2:tcp://localhost:8888/" + baseDir + "/servlet", getUser(), getPassword());
error("Unexpected success");
} catch (SQLException e) {
checkNotGeneralException(e);
}
// connection must be closed
try {
stat1.execute("SELECT * FROM DUAL");
error("Unexpected success");
} catch (SQLException e) {
checkNotGeneralException(e);
}
}
}
......@@ -525,3 +525,4 @@ compares packets destroying echo homed hosts clock countries validated catches t
echo callablestatement procid homed getstart staging prices meantime qujd qujdra qui divided quaere restrictions hudson scoped design inverting newlines
violate verysmallint eremainder iee cgi adjust estimation consumption occupy ikvm light gray viewer grover harpal
upgrading consecutive acting
simulates dispatcher servlets chf destruction separating consulting reached
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论